From: Thomas Mühlbacher Date: Mon, 30 Aug 2021 14:16:30 +0000 (+0200) Subject: man: Don't leak memory in path-documents example X-Git-Tag: v250-rc1~758 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fee1863c83d04aa06d50a90ff42f5d4f4f2b9178;p=thirdparty%2Fsystemd.git man: Don't leak memory in path-documents example The `sd_path_lookup(3)` man page states that the returned string shall be `free(3)`'d but then doesn't do so in the example code. Also add basic error handling as well. --- diff --git a/man/path-documents.c b/man/path-documents.c index a6c1f9371ae..082d6c29fb4 100644 --- a/man/path-documents.c +++ b/man/path-documents.c @@ -1,9 +1,17 @@ #include +#include #include int main(void) { + int r; char *t; - sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t); + r = sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t); + if (r < 0) + return EXIT_FAILURE; + printf("~/Documents: %s\n", t); + free(t); + + return EXIT_SUCCESS; }