Modernization

Fixes minor leak in error path in device.c.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-10-13 17:56:54 -04:00
parent 7ff7394d9e
commit b47d419c25
9 changed files with 70 additions and 101 deletions
+4 -11
View File
@@ -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;
+3 -7
View File
@@ -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;
}
+2 -2
View File
@@ -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)
+10 -7
View File
@@ -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;
}
+1 -3
View File
@@ -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;
}