Skip to content

Commit fee1863

Browse files
tmuehlbacheryuwata
authored andcommitted
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.
1 parent 827d1ba commit fee1863

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

man/path-documents.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#include <stdio.h>
2+
#include <stdlib.h>
23
#include <sd-path.h>
34

45
int main(void) {
6+
int r;
57
char *t;
68

7-
sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t);
9+
r = sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t);
10+
if (r < 0)
11+
return EXIT_FAILURE;
12+
813
printf("~/Documents: %s\n", t);
14+
free(t);
15+
16+
return EXIT_SUCCESS;
917
}

0 commit comments

Comments
 (0)