Ran a grep to find unneccessary NULL checks before free(3) and found
some in dhclient(8) and makefs(8).

Geoff Hill


Index: sbin/dhclient/dhclient.c
===================================================================
RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.659
diff -u -p -r1.659 dhclient.c
--- sbin/dhclient/dhclient.c    26 Jan 2020 10:31:03 -0000      1.659
+++ sbin/dhclient/dhclient.c    7 Apr 2020 23:38:50 -0000
@@ -2315,8 +2315,7 @@ fork_privchld(struct interface_info *ifi
 
        go_daemon();
 
-       if (log_procname != NULL)
-               free(log_procname);
+       free(log_procname);
        rslt = asprintf(&log_procname, "%s [priv]", ifi->name);
        if (rslt == -1)
                fatal("log_procname");
Index: usr.sbin/makefs/ffs.c
===================================================================
RCS file: /cvs/src/usr.sbin/makefs/ffs.c,v
retrieving revision 1.31
diff -u -p -r1.31 ffs.c
--- usr.sbin/makefs/ffs.c       21 Jan 2017 21:58:32 -0000      1.31
+++ usr.sbin/makefs/ffs.c       7 Apr 2020 23:38:52 -0000
@@ -448,8 +448,7 @@ ffs_create_image(const char *image, fsin
                }
                bufrem -= i;
        }
-       if (buf)
-               free(buf);
+       free(buf);
 
                /* make the file system */
        if (Tflag) {
@@ -706,8 +705,7 @@ ffs_populate_dir(const char *dir, fsnode
        }
 
                /* cleanup */
-       if (dirbuf.buf != NULL)
-               free(dirbuf.buf);
+       free(dirbuf.buf);
        return (1);
 }
 
@@ -803,8 +801,7 @@ ffs_write_file(union dinode *din, uint32
        ffs_write_inode(&in.i_din, in.i_number, fsopts);
 
  leave_ffs_write_file:
-       if (fbuf)
-               free(fbuf);
+       free(fbuf);
        if (ffd != -1)
                close(ffd);
 }

Reply via email to