unnecessary "if-before-free" tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Dan,

I noticed a few new unnecessary "if-before-free" tests:

  src/storage_backend.c:2591: if (groups[j]) free(groups[j]);
  src/storage_backend_iscsi.c:    if (devpath) free(devpath);
  src/storage_backend_iscsi.c:    if (portal) free(portal);
  src/storage_backend_iscsi.c:    if (session) free(session);

FYI, this finds all the one-liners:

  git grep -E 'if \(([^)]+)\) free *\(\1\)'

I had to think harder to get the 2-line occurrences:

perl -0ne '/\b(if \(([^)]+)\)\s+free *\(\2\))/sgm and print "$ARGV:$.: $1\n"'\
  $(git ls-files)

or rather this, if you don't have a git repo handy:

perl -0ne '/\b(if \(([^)]+)\)\s+free *\(\2\))/sgm and print "$ARGV:$.: $1\n"'\
  {src,tests,qemud,proxy}/*.[ch]

If no one objects, I'm going to remove them
and add a build-time test to ensure they stay gone.

------------------
gnulib/lib/getaddrinfo.c:2257: if (cur->ai_canonname) free (cur->ai_canonname)
gnulib/lib/printf-parse.c:2277: if (a->arg)
    free (a->arg)
proxy/libvirt_proxy.c:2499: if (name)
                free(name)
qemud/qemud.c:2529: if (client->saslUsername) free(client->saslUsername)
src/buf.c:2549: if (buf->content)
            free(buf->content)
src/conf.c:2551: if (tmp->comment)
            free(tmp->comment)
src/hash.c:2559: if (iter->name)
                    free(iter->name)
src/iptables.c:2562: if (rule->rule)
        free(rule->rule)
src/libvirt.c:2566: if (ret->name) free (ret->name)
src/openvz_conf.c:2570: if (prop)
        free(prop)
src/qemu_conf.c:2578: if (prop)
        free(prop)
src/qemu_driver.c:2580: if (base) free (base)
src/remote_internal.c:2584: if (name) free (name)
src/storage_backend.c:2591: if (groups[j]) free(groups[j])
src/storage_backend_iscsi.c:2597: if (devpath) free(devpath)
src/storage_conf.c:2605: if (def->name)
        free(def->name)
src/storage_driver.c:2607: if (base) free (base)
src/test.c:2609: if (name)
        free(name)
src/virsh.c:2615: if (ctl->name)
        free(ctl->name)
src/xen_internal.c:2617: if (new)
            free(new)
src/xend_internal.c:2621: if (drvName)
                free(drvName)
src/xm_internal.c:2623: if (vif)
                    free(vif)
src/xml.c:2625: if (str)
        free(str)
src/xmlrpc.c:2627: if (value)
        free(value)
tests/testutils.c:2739: if (ts)
        free(ts)
tests/xencapstest.c:2784: if (actualxml)
    free(actualxml)
tests/xmconfigtest.c:2804: if (gotxml)
        free(gotxml)

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]