]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Bug #944: Deletion of unnecessary checks before calls of the function "free"
authorMarkus Elfring <elfring@users.sourceforge.net>
Mon, 17 Aug 2015 07:30:49 +0000 (09:30 +0200)
committerMarkus Elfring <elfring@users.sourceforge.net>
Mon, 17 Aug 2015 07:30:49 +0000 (09:30 +0200)
The function "free" is documented in the way that no action shall occur for
a passed null pointer. It is therefore not needed that a function caller
repeats a corresponding check.
http://stackoverflow.com/questions/18775608/free-a-null-pointer-anyway-or-check-first

This issue was fixed by using the software Coccinelle 1.0.1.

src/journal/journal-file.c
src/udev/udev-builtin-path_id.c

index f7815b27961c251cff428ee5e3d9cd391b4a50d8..4f94799ce74708dbbb6b7536f19336043f1154f4 100644 (file)
@@ -169,7 +169,7 @@ void journal_file_close(JournalFile *f) {
 #ifdef HAVE_GCRYPT
         if (f->fss_file)
                 munmap(f->fss_file, PAGE_ALIGN(f->fss_file_size));
-        else if (f->fsprg_state)
+        else
                 free(f->fsprg_state);
 
         free(f->fsprg_seed);
index aa5cda6fe77fc85a53e5e1e9320fe97a0cd33dda..f529ffcf256d8688479c924d9dc5f247aa64fa34 100644 (file)
@@ -117,8 +117,7 @@ static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent,
 
         format_lun_number(parent, &lun);
         path_prepend(path, "fc-%s-%s", port, lun);
-        if (lun)
-                free(lun);
+        free(lun);
 out:
         udev_device_unref(fcdev);
         return parent;
@@ -156,8 +155,7 @@ static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent,
 
         format_lun_number(parent, &lun);
         path_prepend(path, "sas-%s-%s", sas_address, lun);
-        if (lun)
-                free(lun);
+        free(lun);
 out:
         udev_device_unref(sasdev);
         return parent;
@@ -251,8 +249,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
         else
                  path_prepend(path, "sas-phy%s-%s", phy_id, lun);
 
-        if (lun)
-                free(lun);
+        free(lun);
 out:
         udev_device_unref(target_sasdev);
         udev_device_unref(expander_sasdev);
@@ -313,8 +310,7 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **
 
         format_lun_number(parent, &lun);
         path_prepend(path, "ip-%s:%s-iscsi-%s-%s", addr, port, target, lun);
-        if (lun)
-                free(lun);
+        free(lun);
 out:
         udev_device_unref(sessiondev);
         udev_device_unref(conndev);