memory: ensure to check allocation results#3084
memory: ensure to check allocation results#3084danielgustafsson wants to merge 3 commits intocurl:masterfrom
Conversation
The result of a memory allocation should always be checked, as we may run under memory pressure where even a small allocation can fail. This adds checking and error handling to a few cases where the allocation wasn't checked for success. Also bumps the copyright years on affected files.
|
you don't need this pattern if(foo)free(foo) just free(foo). also the second one i think the lock needs to be freed as well and for that you do need if(foo)NXMutexFree(foo) |
Spotted by Jay Satiro
Right, I was mainly following the style of the surrounding code there, to make the flow easier to read.
Nice catch, have pushed a fixup commit with this. |
In the unlikely event that strdup() fails for (""), ensure to error
our with the appropriate errorcode. Also move freeing path up to
above the strdup() call since there is little point in keeping it
around across the strdup, and the separation makes for more readable
code.
|
Pulled in the related |
There is no need for a conditional there, just free(foo) is fine. Other than that LGTM |
The result of a memory allocation should always be checked, as we may run under memory pressure where even a small allocation can fail. This adds checking and error handling to a few cases where the allocation wasn't checked for success. Also bumps the copyright years on affected files.
This is based on manual static analysis/code reading, no live bugs have been observed.