[Libvir] unnecessary "if-before-free" tests

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)

On Mon, Jan 21, 2008 at 06:53:52PM +0100, Jim Meyering wrote:
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);
There's a hell of alot more than those 4 in the storage code - most are 2-liners. I'll kill them all off.
If no one objects, I'm going to remove them and add a build-time test to ensure they stay gone.
Fine with me. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
participants (2)
-
Daniel P. Berrange
-
Jim Meyering