aboutsummaryrefslogtreecommitdiffstats
path: root/man7
diff options
context:
space:
mode:
authorMarko Hrastovec <marko.hrastovec@gmail.com>2020-09-17 07:33:32 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2020-09-17 09:12:24 +0200
commita23b00988ae023f18bd31f18ab2fd32230637ce2 (patch)
treea7085bc3c2da850e86711c6142f1f1f6ebee99a0 /man7
parent966d17b1c5916b2804e61834c8349ab59cfcd94e (diff)
downloadman-pages-a23b00988ae023f18bd31f18ab2fd32230637ce2.tar.gz
freeaddrinfo.3: Fix memory leaks in freeaddrinfo() examples
[mtk: the coding style used in the example could lead people to inject memory leaks in their code if they cut/paste/modify the code to replace "exit" paths with "return" paths from a library function.] [Marko, from the mail thread discussing this patch:] You are right about terminating the process. However, people copy that example and put the code in a function changing "exit" to "return". There are a bunch of examples like that here https://beej.us/guide/bgnet/html/#poll, for instance. That error bothered me when reading the network programming guide https://beej.us/guide/bgnet/html/. Than I looked for information elsewhere: https://stackoverflow.com/questions/6712740/valgrind-reporting-that-getaddrinfo-is-leaking-memory https://stackoverflow.com/questions/15690303/server-client-sockets-freeaddrinfo3-placement And finally, I checked manual pages and saw where these errors come from. When you change that to a function and return without doing freeaddrinfo, that is a memory leak. I believe an example should show good programming practices. Relying on exiting and clearing the memory in that case is not such a case. In my opinion, these examples lead people to make mistakes in their programs. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man7')
0 files changed, 0 insertions, 0 deletions