dbry / WavPack

WavPack encode/decode library, command-line programs, and several plugins
BSD 3-Clause "New" or "Revised" License
346 stars 65 forks source link

fixing a possible memory leak. #88

Closed ihsinme closed 3 years ago

ihsinme commented 3 years ago

the form of using the realloc function can lead to the loss of a pointer to previously allocated memory.

the suggested fixes will eliminate this issue.

dbry commented 3 years ago

Hi, and thanks for pointing this out!

I agree that this is technically incorrect, but I feel that this is actually a non-issue. If a small allocation like that fails then there is something seriously wrong with the system and the process is likely to be shut down very soon (which will free everything). I don't think the extra code to handle this is worth it, especially considering that out-of-memory is not handled gracefully by the library anyway and there are many other instances of this exact same pattern.

ihsinme commented 3 years ago

yes you are to a degree right. but I researched 33 similar places in your code except 3, they all immediately lead to an exception and really have no effect on the leak. however, for example in the corrected file open_utils.c, in 2 places the allocated memory is checked for NULL equality. which suggests that the author is ready for this situation. Moreover, these checks do not terminate the program.

so I propose to consider this PR.