From fee1863c83d04aa06d50a90ff42f5d4f4f2b9178 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BChlbacher?= Date: Mon, 30 Aug 2021 16:16:30 +0200 Subject: [PATCH] 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. --- man/path-documents.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/man/path-documents.c b/man/path-documents.c index a6c1f9371a..082d6c29fb 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; } -- 2.25.1