summaryrefslogtreecommitdiff
path: root/man/path-documents.c
diff options
context:
space:
mode:
authorThomas Mühlbacher <tmuehlbacher@posteo.net>2021-08-30 16:16:30 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-08-31 13:44:49 +0900
commitfee1863c83d04aa06d50a90ff42f5d4f4f2b9178 (patch)
tree917d55f1581591f0d559e7a956934f355babc913 /man/path-documents.c
parent827d1ba7304600b0272583818f479bdbd5e45493 (diff)
downloadsystemd-fee1863c83d04aa06d50a90ff42f5d4f4f2b9178.tar.gz
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.
Diffstat (limited to 'man/path-documents.c')
-rw-r--r--man/path-documents.c10
1 files changed, 9 insertions, 1 deletions
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 <stdio.h>
+#include <stdlib.h>
#include <sd-path.h>
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;
}