mirror of
https://github.com/systemd/systemd
synced 2024-09-06 00:41:36 +00: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 <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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue