logind: use _cleanup_ in one more place

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-09-22 17:33:24 +02:00
parent d52e1c420c
commit 0a9bf7fa59
1 changed files with 6 additions and 16 deletions

View File

@ -3195,7 +3195,6 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
_cleanup_free_ char *id = NULL; _cleanup_free_ char *id = NULL;
_cleanup_close_ int fifo_fd = -1; _cleanup_close_ int fifo_fd = -1;
Manager *m = userdata; Manager *m = userdata;
Inhibitor *i = NULL;
InhibitMode mm; InhibitMode mm;
InhibitWhat w; InhibitWhat w;
pid_t pid; pid_t pid;
@ -3278,6 +3277,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
} while (hashmap_get(m->inhibitors, id)); } while (hashmap_get(m->inhibitors, id));
_cleanup_(inhibitor_freep) Inhibitor *i = NULL;
r = manager_add_inhibitor(m, id, &i); r = manager_add_inhibitor(m, id, &i);
if (r < 0) if (r < 0)
return r; return r;
@ -3289,28 +3289,18 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
i->why = strdup(why); i->why = strdup(why);
i->who = strdup(who); i->who = strdup(who);
if (!i->why || !i->who) { if (!i->why || !i->who)
r = -ENOMEM; return -ENOMEM;
goto fail;
}
fifo_fd = inhibitor_create_fifo(i); fifo_fd = inhibitor_create_fifo(i);
if (fifo_fd < 0) { if (fifo_fd < 0)
r = fifo_fd; return fifo_fd;
goto fail;
}
r = inhibitor_start(i); r = inhibitor_start(i);
if (r < 0) if (r < 0)
goto fail; return r;
return sd_bus_reply_method_return(message, "h", fifo_fd); return sd_bus_reply_method_return(message, "h", fifo_fd);
fail:
if (i)
inhibitor_free(i);
return r;
} }
static const sd_bus_vtable manager_vtable[] = { static const sd_bus_vtable manager_vtable[] = {