diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-objects.c | 10 | ||||
-rw-r--r-- | src/sleep/sleep.c | 15 | ||||
-rw-r--r-- | src/udev/net/link-config.c | 2 |
3 files changed, 13 insertions, 14 deletions
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c index 8c81ea6641..5aa83a4426 100644 --- a/src/libsystemd-bus/bus-objects.c +++ b/src/libsystemd-bus/bus-objects.c @@ -1338,7 +1338,8 @@ int bus_process_object(sd_bus *bus, sd_bus_message *m) { static struct node *bus_node_allocate(sd_bus *bus, const char *path) { struct node *n, *parent; const char *e; - char *s, *p; + _cleanup_free_ char *s = NULL; + char *p; int r; assert(bus); @@ -1366,10 +1367,8 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) { p = strndupa(path, MAX(1, path - e)); parent = bus_node_allocate(bus, p); - if (!parent) { - free(s); + if (!parent) return NULL; - } } n = new0(struct node, 1); @@ -1378,10 +1377,11 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) { n->parent = parent; n->path = s; + s = NULL; /* do not free */ r = hashmap_put(bus->nodes, s, n); if (r < 0) { - free(s); + free(n->path); free(n); return NULL; } diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index b6a6f60d03..bf673549f1 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -57,15 +57,14 @@ static int write_mode(char **modes) { return r; } -static int write_state(FILE *f0, char **states) { - FILE _cleanup_fclose_ *f = f0; +static int write_state(FILE **f, char **states) { char **state; int r = 0; STRV_FOREACH(state, states) { int k; - k = write_string_to_file(f, *state); + k = write_string_to_file(*f, *state); if (k == 0) return 0; log_debug("Failed to write '%s' to /sys/power/state: %s", @@ -73,9 +72,9 @@ static int write_state(FILE *f0, char **states) { if (r == 0) r = k; - fclose(f); - f = fopen("/sys/power/state", "we"); - if (!f) { + fclose(*f); + *f = fopen("/sys/power/state", "we"); + if (!*f) { log_error("Failed to open /sys/power/state: %m"); return -errno; } @@ -87,7 +86,7 @@ static int write_state(FILE *f0, char **states) { static int execute(char **modes, char **states) { char* arguments[4]; int r; - FILE *f; + _cleanup_fclose_ FILE *f = NULL; const char* note = strappenda("SLEEP=", arg_verb); /* This file is opened first, so that if we hit an error, @@ -115,7 +114,7 @@ static int execute(char **modes, char **states) { note, NULL); - r = write_state(f, states); + r = write_state(&f, states); if (r < 0) return r; diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index f25afa60c7..1a9d780a67 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -149,7 +149,7 @@ void link_config_ctx_free(link_config_ctx *ctx) { static int load_link(link_config_ctx *ctx, const char *filename) { link_config *link; - FILE *file; + _cleanup_fclose_ FILE *file; int r; file = fopen(filename, "re"); |