org-arl / unet-contrib

Unet user contributions
BSD 3-Clause "New" or "Revised" License
11 stars 15 forks source link

fix(unetsocket.c): manually initialising malloced structures. #56

Closed notthetup closed 3 years ago

notthetup commented 3 years ago

Pending : Test on Windows

prasadtiru commented 3 years ago

The file on which you have made changes doesn't seem to be one from the master. Did you branch off from master, made changes and created this PR ? Could you re-check ? In the latest unet.c, the change you have made should be on line 151 (https://github.com/org-arl/unet-contrib/blob/master/unetsocket/c/unet.c#L151)

notthetup commented 3 years ago

Thanks @prasadtiru fixed it.

prasadtiru commented 3 years ago

Tested this change on Windows. Works fine.

notthetup commented 3 years ago

Agreed. I will refactor back to malloc and manually initializing all fields. I prefer that too.

In this case, it's just 4 malloc calls, so tracing them and figuring out what the manual initialization needs to be is simple. For larger libraries like fjage.c it is more tedious to verify if malloced memory needs manual initialization etc. Hence my conclusion to jump to calloc. It's simpler and safer and less likely to create leaks and memory-related bugs.

notthetup commented 3 years ago

Updated with only "zeroing" the relevant properties.