mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
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:
parent
827d1ba730
commit
fee1863c83
@ -1,9 +1,17 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sd-path.h>
|
#include <sd-path.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
int r;
|
||||||
char *t;
|
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);
|
printf("~/Documents: %s\n", t);
|
||||||
|
free(t);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user