c++ - Is there a fix or a workaround for the memory leak in getpwnam? -
is there fix or workaround memory leak in getpwnam?
getpwnam()
does not suffer of memory leak. subsequent calls, indeed, overwrite static internal buffer.
such kind of functions instead non-reentrant , therefore non-thread safe. paul suggested use of getpwnam_r()
reentrant version, safe used in multithread context.
that said, memory leaks caused system calls allocate memory means of malloc()
, leave application responsability free()
memory once returned data has used.
in these cases raii idiom advisable in order not forget free allocated memory -- see exception safety. std::tr1::shared_ptr<>
viable way: shared_ptr custom deleter must provided free()
raw pointer when shared_ptr goes out of scope.
under perspective dangerous functions scandir()
, asprintf()
, vasprintf()
etc.
Comments
Post a Comment