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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -