You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The parseRequest function creates multiple potential memory leaks.
Description
parseRequestcurrently unconditionally allocates new memory and stores the resulting pointers in resultArray, overwriting any pointers already stored there. This can leak memory in two ways. First, the allocation may overwrite a pointer without freeing it. This was previously handled by freeing non-null pointers in resultArray, but parseRequest is sometimes called with a stack allocated two dimensional array, which causes free to segfault on Windows 8. Second, the responsibility for eventually freeing the newly allocated memory falls to the caller. Since there is no way to enforce this contract, it is inevitable that callers will forget to free memory.
The text was updated successfully, but these errors were encountered:
Require that the caller pass resultArray with enough memory already allocated. This makes it the explicit responsibility of the caller to handle all memory management, but it opens the door to buffer overflows since there is now way for parseRequest to verify that the size of the arrays stored in resultArray are correct.
Require that the caller pass resultArray with either NULL or valid heap allocated arrays. This allows us to safely call free before re-assigning new allocations to resultArray, but still leave the potential for the caller to forget to free the resulting allocations. It could also be an issue if the caller has another pointer to one of the existing results.
Leave the function as is. Assume the caller knows what they are doing, and let them sort out any memory management issues.
In any of the three cases, the contract for this function probably needs to be stated very explicitly to reduce the likelihood of memory management errors.
Latest version of the C client make substantial architectural changes to prevent this kind of issue from cropping up in the future. All client functions now require that memory be fully allocated when passed as an argument, and uses additional parameters to ensure that the arguments are sufficiently large to handle the requested data.
Summary
The
parseRequest
function creates multiple potential memory leaks.Description
parseRequest
currently unconditionally allocates new memory and stores the resulting pointers inresultArray
, overwriting any pointers already stored there. This can leak memory in two ways. First, the allocation may overwrite a pointer without freeing it. This was previously handled by freeing non-null pointers inresultArray
, butparseRequest
is sometimes called with a stack allocated two dimensional array, which causesfree
to segfault on Windows 8. Second, the responsibility for eventually freeing the newly allocated memory falls to the caller. Since there is no way to enforce this contract, it is inevitable that callers will forget to free memory.The text was updated successfully, but these errors were encountered: