Closed goriy closed 9 years ago
if available you can use reallocf for that, if not you can create an inline function..
reallocf
seems to be available on BSD systems only, I would not rely on that.
But inline function wrapping realloc
would be a nice improvement for this PR to avoid code duplication.
I agree that usage of non-standard reallocf
function is not so good idea. It's not very likely that reallocf
function is present in stdlib for most embedded platforms, for example.
I've added tiny inline wrapper function.
When realloc() function fails it returns NULL pointer. But old data pointer remains valid in such a case.
It's a mistake to use old data pointer to store new pointer returned by realloc. In case of realloc failure, pointer is overwritten with NULL value, but old used memory remains unreferenced and could not be even freed anymore. Such mistakes could lead to memory leaks.