tsearch.3: dispose properly of allocated resources in example code
PATCH 1/1 tsearch.3: dispose properly of allocated resources in example code
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.
tsearch.3.goddard renamed from tsearch.3 +3 -0
@@ -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