diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-12 12:15:49 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-13 17:56:54 -0400 |
commit | b47d419c25ecc735615a1088060c1ec8bef1e41f (patch) | |
tree | 13940040841fbec3a928f82426390654e4b50fcc /src/shared | |
parent | 7ff7394d9e4e9189c30fd018235e6b1728c6f2d0 (diff) |
Modernization
Fixes minor leak in error path in device.c.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cgroup-show.c | 15 | ||||
-rw-r--r-- | src/shared/efivars.c | 10 | ||||
-rw-r--r-- | src/shared/install.c | 4 | ||||
-rw-r--r-- | src/shared/socket-util.c | 17 | ||||
-rw-r--r-- | src/shared/util.c | 4 |
5 files changed, 20 insertions, 30 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index cc44ab4ea9..979fa8fddf 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -67,7 +67,7 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi /* And sort */ qsort(pids, n_pids, sizeof(pid_t), compare); - if(flags & OUTPUT_FULL_WIDTH) + if (flags & OUTPUT_FULL_WIDTH) n_columns = 0; else { if (n_columns > pid_width+2) @@ -76,7 +76,7 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi n_columns = 20; } for (i = 0; i < n_pids; i++) { - char *t = NULL; + _cleanup_free_ char *t = NULL; get_process_cmdline(pids[i], n_columns, true, &t); @@ -87,8 +87,6 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi pid_width, (unsigned long) pids[i], strna(t)); - - free(t); } } @@ -98,7 +96,7 @@ static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigne _cleanup_fclose_ FILE *f = NULL; size_t n = 0, n_allocated = 0; _cleanup_free_ pid_t *pids = NULL; - char *p = NULL; + _cleanup_free_ char *p = NULL; pid_t pid; int r; @@ -106,13 +104,8 @@ static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigne if (r < 0) return r; - fn = strappend(p, "/cgroup.procs"); - free(p); - if (!fn) - return -ENOMEM; - + fn = strappenda(p, "/cgroup.procs"); f = fopen(fn, "re"); - free(fn); if (!f) return -errno; diff --git a/src/shared/efivars.c b/src/shared/efivars.c index f3eb6a6e5d..000dae9de0 100644 --- a/src/shared/efivars.c +++ b/src/shared/efivars.c @@ -37,7 +37,7 @@ bool is_efi_boot(void) { static int read_flag(const char *varname) { int r; - void *v; + _cleanup_free_ void *v = NULL; size_t s; uint8_t b; @@ -45,15 +45,11 @@ static int read_flag(const char *varname) { if (r < 0) return r; - if (s != 1) { - r = -EINVAL; - goto finish; - } + if (s != 1) + return -EINVAL; b = *(uint8_t *)v; r = b > 0; -finish: - free(v); return r; } diff --git a/src/shared/install.c b/src/shared/install.c index 9722ed4e1c..5a780fe915 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1874,6 +1874,7 @@ static void unitfilelist_free(UnitFileList **f) { free((*f)->path); free(*f); } +#define _cleanup_unitfilelist_free_ _cleanup_(unitfilelist_free) int unit_file_get_list( UnitFileScope scope, @@ -1925,8 +1926,7 @@ int unit_file_get_list( for (;;) { struct dirent *de; union dirent_storage buffer; - UnitFileList __attribute__((cleanup(unitfilelist_free))) - *f = NULL; + _cleanup_unitfilelist_free_ UnitFileList *f = NULL; r = readdir_r(d, &buffer.de, &de); if (r != 0) diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 9224208244..954686f974 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -300,7 +300,8 @@ int socket_address_print(const SocketAddress *a, char **p) { case AF_INET: { char *ret; - if (!(ret = new(char, INET_ADDRSTRLEN+1+5+1))) + ret = new(char, INET_ADDRSTRLEN+1+5+1); + if (!ret) return -ENOMEM; if (!inet_ntop(AF_INET, &a->sockaddr.in4.sin_addr, ret, INET_ADDRSTRLEN)) { @@ -316,7 +317,8 @@ int socket_address_print(const SocketAddress *a, char **p) { case AF_INET6: { char *ret; - if (!(ret = new(char, 1+INET6_ADDRSTRLEN+2+5+1))) + ret = new(char, 1+INET6_ADDRSTRLEN+2+5+1); + if (!ret) return -ENOMEM; ret[0] = '['; @@ -334,8 +336,8 @@ int socket_address_print(const SocketAddress *a, char **p) { char *ret; if (a->size <= offsetof(struct sockaddr_un, sun_path)) { - - if (!(ret = strdup("<unnamed>"))) + ret = strdup("<unnamed>"); + if (!ret) return -ENOMEM; } else if (a->sockaddr.un.sun_path[0] == 0) { @@ -346,7 +348,8 @@ int socket_address_print(const SocketAddress *a, char **p) { * more than one NUL byte. That is * actually an invalid assumption */ - if (!(ret = new(char, sizeof(a->sockaddr.un.sun_path)+1))) + ret = new(char, sizeof(a->sockaddr.un.sun_path)+1); + if (!ret) return -ENOMEM; ret[0] = '@'; @@ -354,8 +357,8 @@ int socket_address_print(const SocketAddress *a, char **p) { ret[sizeof(a->sockaddr.un.sun_path)] = 0; } else { - - if (!(ret = strdup(a->sockaddr.un.sun_path))) + ret = strdup(a->sockaddr.un.sun_path); + if (!ret) return -ENOMEM; } diff --git a/src/shared/util.c b/src/shared/util.c index e18421e520..54dbace193 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -643,7 +643,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * /* Kernel threads have no argv[] */ if (r == NULL || r[0] == 0) { - char *t; + _cleanup_free_ char *t = NULL; int h; free(r); @@ -656,8 +656,6 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * return h; r = strjoin("[", t, "]", NULL); - free(t); - if (!r) return -ENOMEM; } |