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.
This commit is contained in:
Thomas Mühlbacher 2021-08-30 16:16:30 +02:00 committed by Yu Watanabe
parent 827d1ba730
commit fee1863c83

View file

@ -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;
}