From: "André Goddard Rosa" <andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Subject: [patch] tsearch.3: dispose properly of allocated resources in example code
Date: Sun, 21 Sep 2008 03:15:21 -0300 [thread overview]
Message-ID: <200809210315.21860.andre.goddard@gmail.com> (raw)
As there are many users who base their own code on these examples, we should avoid leaking memory when using functions of tsearch() family.
In the provided example, tsearch() leaks memory whenever it tries to insert a number which was already inserted before.
Please CC me, as I´m not subscribed.
Applies to man-pages-3.09.
--- man3/tsearch.3 2008-09-10 10:16:13.000000000 -0300
+++ man3/tsearch.3.goddard 2008-09-21 03:12:43.000000000 -0300
@@ -246,8 +246,11 @@
val = tsearch((void *) ptr, &root, compare);
if (val == NULL)
exit(EXIT_FAILURE);
+ else if ((*(int **) val) != ptr)
+ free(ptr);
}
twalk(root, action);
+ tdestroy(root, free);
exit(EXIT_SUCCESS);
}
.fi
\0
next reply other threads:[~2008-09-21 6:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-21 6:15 André Goddard Rosa [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-09-21 6:10 [patch] tsearch.3: dispose properly of allocated resources in example code André Goddard Rosa
[not found] ` <200809210310.43647.andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2008-09-23 6:28 ` Michael Kerrisk
[not found] ` <cfd18e0f0809222328r599e22c1je0f4261ee969bca8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-09-23 13:23 ` André Goddard Rosa
[not found] ` <b8bf37780809230623k62d43d6cgf11af4820566cd2d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-09-23 13:56 ` Michael Kerrisk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200809210315.21860.andre.goddard@gmail.com \
--to=andre.goddard-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox