use more _cleanup_ macro

This commit is contained in:
Ronny Chevalier 2014-06-24 19:00:32 +02:00 committed by Tom Gundersen
parent 6ec60d2072
commit e1d758033d
8 changed files with 16 additions and 43 deletions

View file

@ -144,7 +144,7 @@ static int automount_add_default_dependencies(Automount *a) {
static int automount_verify(Automount *a) { static int automount_verify(Automount *a) {
bool b; bool b;
char *e; _cleanup_free_ char *e = NULL;
assert(a); assert(a);
if (UNIT(a)->load_state != UNIT_LOADED) if (UNIT(a)->load_state != UNIT_LOADED)
@ -160,7 +160,6 @@ static int automount_verify(Automount *a) {
return -ENOMEM; return -ENOMEM;
b = unit_has_name(UNIT(a), e); b = unit_has_name(UNIT(a), e);
free(e);
if (!b) { if (!b) {
log_error_unit(UNIT(a)->id, "%s's Where setting doesn't match unit name. Refusing.", UNIT(a)->id); log_error_unit(UNIT(a)->id, "%s's Where setting doesn't match unit name. Refusing.", UNIT(a)->id);

View file

@ -561,7 +561,7 @@ static int restore_confirm_stdio(int *saved_stdin,
static int ask_for_confirmation(char *response, char **argv) { static int ask_for_confirmation(char *response, char **argv) {
int saved_stdout = -1, saved_stdin = -1, r; int saved_stdout = -1, saved_stdin = -1, r;
char *line; _cleanup_free_ char *line = NULL;
r = setup_confirm_stdio(&saved_stdin, &saved_stdout); r = setup_confirm_stdio(&saved_stdin, &saved_stdout);
if (r < 0) if (r < 0)
@ -572,7 +572,6 @@ static int ask_for_confirmation(char *response, char **argv) {
return -ENOMEM; return -ENOMEM;
r = ask(response, "yns", "Execute %s? [Yes, No, Skip] ", line); r = ask(response, "yns", "Execute %s? [Yes, No, Skip] ", line);
free(line);
restore_confirm_stdio(&saved_stdin, &saved_stdout); restore_confirm_stdio(&saved_stdin, &saved_stdout);
@ -2058,8 +2057,8 @@ int exec_context_load_environment(const ExecContext *c, char ***l) {
} }
static bool tty_may_match_dev_console(const char *tty) { static bool tty_may_match_dev_console(const char *tty) {
char *active = NULL, *console; _cleanup_free_ char *active = NULL;
bool b; char *console;
if (startswith(tty, "/dev/")) if (startswith(tty, "/dev/"))
tty += 5; tty += 5;
@ -2074,10 +2073,7 @@ static bool tty_may_match_dev_console(const char *tty) {
return true; return true;
/* "tty0" means the active VC, so it may be the same sometimes */ /* "tty0" means the active VC, so it may be the same sometimes */
b = streq(console, tty) || (streq(console, "tty0") && tty_is_vc(tty)); return streq(console, tty) || (streq(console, "tty0") && tty_is_vc(tty));
free(active);
return b;
} }
bool exec_context_may_touch_console(ExecContext *ec) { bool exec_context_may_touch_console(ExecContext *ec) {
@ -2467,10 +2463,10 @@ char *exec_command_line(char **argv) {
} }
void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) { void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) {
char *p2; _cleanup_free_ char *p2 = NULL;
const char *prefix2; const char *prefix2;
char *cmd; _cleanup_free_ char *cmd = NULL;
assert(c); assert(c);
assert(f); assert(f);
@ -2486,11 +2482,7 @@ void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) {
"%sCommand Line: %s\n", "%sCommand Line: %s\n",
prefix, cmd ? cmd : strerror(ENOMEM)); prefix, cmd ? cmd : strerror(ENOMEM));
free(cmd);
exec_status_dump(&c->exec_status, f, prefix2); exec_status_dump(&c->exec_status, f, prefix2);
free(p2);
} }
void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix) { void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix) {

View file

@ -202,7 +202,7 @@ static int killall(int sig, Set *pids, bool send_sighup) {
void broadcast_signal(int sig, bool wait_for_exit, bool send_sighup) { void broadcast_signal(int sig, bool wait_for_exit, bool send_sighup) {
sigset_t mask, oldmask; sigset_t mask, oldmask;
Set *pids = NULL; _cleanup_set_free_ Set *pids = NULL;
if (wait_for_exit) if (wait_for_exit)
pids = set_new(trivial_hash_func, trivial_compare_func); pids = set_new(trivial_hash_func, trivial_compare_func);
@ -223,6 +223,4 @@ void broadcast_signal(int sig, bool wait_for_exit, bool send_sighup) {
wait_for_children(pids, &mask); wait_for_children(pids, &mask);
assert_se(sigprocmask(SIG_SETMASK, &oldmask, NULL) == 0); assert_se(sigprocmask(SIG_SETMASK, &oldmask, NULL) == 0);
set_free(pids);
} }

View file

@ -126,9 +126,8 @@ static int mount_points_list_get(MountPoint **head) {
} }
static int swap_list_get(MountPoint **head) { static int swap_list_get(MountPoint **head) {
FILE *proc_swaps; _cleanup_fclose_ FILE *proc_swaps = NULL;
unsigned int i; unsigned int i;
int r;
assert(head); assert(head);
@ -168,26 +167,19 @@ static int swap_list_get(MountPoint **head) {
free(dev); free(dev);
if (!d) { if (!d) {
r = -ENOMEM; return -ENOMEM;
goto finish;
} }
if (!(swap = new0(MountPoint, 1))) { if (!(swap = new0(MountPoint, 1))) {
free(d); free(d);
r = -ENOMEM; return -ENOMEM;
goto finish;
} }
swap->path = d; swap->path = d;
LIST_PREPEND(mount_point, *head, swap); LIST_PREPEND(mount_point, *head, swap);
} }
r = 0; return 0;
finish:
fclose(proc_swaps);
return r;
} }
static int loopback_list_get(MountPoint **head) { static int loopback_list_get(MountPoint **head) {

View file

@ -98,7 +98,7 @@ static int base_cmp(const void *a, const void *b) {
} }
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) { static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) {
Hashmap *fh; _cleanup_hashmap_free_ Hashmap *fh = NULL;
char **files, **p; char **files, **p;
int r; int r;
@ -116,7 +116,6 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
STRV_FOREACH(p, dirs) { STRV_FOREACH(p, dirs) {
r = files_add(fh, root, *p, suffix); r = files_add(fh, root, *p, suffix);
if (r == -ENOMEM) { if (r == -ENOMEM) {
hashmap_free_free(fh);
return r; return r;
} else if (r < 0) } else if (r < 0)
log_debug("Failed to search for files in %s: %s", log_debug("Failed to search for files in %s: %s",
@ -125,14 +124,12 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
files = hashmap_get_strv(fh); files = hashmap_get_strv(fh);
if (files == NULL) { if (files == NULL) {
hashmap_free_free(fh);
return -ENOMEM; return -ENOMEM;
} }
qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp); qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp);
*strv = files; *strv = files;
hashmap_free(fh);
return 0; return 0;
} }

View file

@ -104,7 +104,7 @@ int fdset_remove(FDSet *s, int fd) {
} }
int fdset_new_fill(FDSet **_s) { int fdset_new_fill(FDSet **_s) {
DIR *d; _cleanup_closedir_ DIR *d = NULL;
struct dirent *de; struct dirent *de;
int r = 0; int r = 0;
FDSet *s; FDSet *s;
@ -150,8 +150,6 @@ int fdset_new_fill(FDSet **_s) {
s = NULL; s = NULL;
finish: finish:
closedir(d);
/* We won't close the fds here! */ /* We won't close the fds here! */
if (s) if (s)
set_free(MAKE_SET(s)); set_free(MAKE_SET(s));

View file

@ -442,7 +442,7 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
}; };
int mount_id, mount_id_parent; int mount_id, mount_id_parent;
char *parent; _cleanup_free_ char *parent = NULL;
struct stat a, b; struct stat a, b;
int r; int r;
@ -473,7 +473,6 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
h.handle.handle_bytes = MAX_HANDLE_SZ; h.handle.handle_bytes = MAX_HANDLE_SZ;
r = name_to_handle_at(AT_FDCWD, parent, &h.handle, &mount_id_parent, 0); r = name_to_handle_at(AT_FDCWD, parent, &h.handle, &mount_id_parent, 0);
free(parent);
if (r < 0) { if (r < 0) {
/* The parent can't do name_to_handle_at() but the /* The parent can't do name_to_handle_at() but the
* directory we are interested in can? If so, it must * directory we are interested in can? If so, it must
@ -504,7 +503,6 @@ fallback:
return r; return r;
r = lstat(parent, &b); r = lstat(parent, &b);
free(parent);
if (r < 0) if (r < 0)
return -errno; return -errno;

View file

@ -1440,7 +1440,7 @@ _pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
} }
int close_all_fds(const int except[], unsigned n_except) { int close_all_fds(const int except[], unsigned n_except) {
DIR *d; _cleanup_closedir_ DIR *d = NULL;
struct dirent *de; struct dirent *de;
int r = 0; int r = 0;
@ -1495,7 +1495,6 @@ int close_all_fds(const int except[], unsigned n_except) {
} }
} }
closedir(d);
return r; return r;
} }