Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should I free pointer returned by getpwuid() in Linux?

Tags:

c

linux

getpwuid

After I call getpwuid(uid), I have a reference to a pointer. Should I free that pointer when I don't use it anymore? Reading the man pages, it says that it makes reference to some static area, that may be overwritten by subsequent calls to the same functions, so I'm not sure if I should touch that memory area.

Thanks.

like image 522
Gabriel Avatar asked Oct 01 '08 23:10

Gabriel


1 Answers

No. You do not need to free the result. You can only call free(3) on pointers allocated on the heap with malloc(3), calloc(3) or realloc(3).

Static data is part of a program's data or bss segments and will persist until the process exits (or is overwritten by exec(2)).

like image 106
camh Avatar answered Oct 19 '22 19:10

camh