core: make unit_free() accept NULL pointers

We generally try to make our destructors robust regarding NULL pointers, much
in the same way as glibc's free(). Do this also for unit_free().

Follow-up for #4748.
This commit is contained in:
Lennart Poettering 2016-11-28 19:41:20 +01:00
parent dc68fed25d
commit c9d5c9c0e1
4 changed files with 5 additions and 4 deletions

View File

@ -359,7 +359,7 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa
fail:
log_unit_warning_errno(u, r, "Failed to set up device unit: %m");
if (delete && u)
if (delete)
unit_free(u);
return r;

View File

@ -1509,7 +1509,7 @@ static int mount_setup_unit(
fail:
log_warning_errno(r, "Failed to set up mount unit: %m");
if (delete && u)
if (delete)
unit_free(u);
return r;

View File

@ -420,7 +420,7 @@ static int swap_setup_unit(
fail:
log_unit_warning_errno(u, r, "Failed to load swap unit: %m");
if (delete && u)
if (delete)
unit_free(u);
return r;

View File

@ -516,7 +516,8 @@ void unit_free(Unit *u) {
Iterator i;
char *t;
assert(u);
if (!u)
return;
if (u->transient_file)
fclose(u->transient_file);