This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: free() vs xfree() vs FREEIF() vs ISO-C


On Nov 30, 12:35pm, Andrew Cagney wrote:

> 	o	Add/use xfree() which
> 		would guard against NULL.
[...]

> Does anyone have any thoughts?  I tend towards the first one as that is
> fairly easy to implement.  If adopted, I'd beg/borrow/con someone into
> converting all free() and free((PTR)) calls into xfree() :-)

I like this approach too.

I've eyeballed the diff output from the script below and it seems to
give pretty good results.  I'll do a test build, and if all is well,
I'll post an rfc patch to gdb-patches.  (Note that this patch doesn't
do any reindenting, but in the diffs I've looked at it, I don't see
a need for it in our present source tree.)

To run this script, just set your current directory to the gdb directory
and then do

    subst-free-xfree .

(note the dot) or do
    
    subst-free-xfree /path/to/gdb/sources

from anywhere.

--- subst-free-xfree ---
#!/usr/bin/perl -w

use File::Find;
use FileHandle;
use IPC::Open3;
use English;

my ($root) = @ARGV;

if (!defined($root)) {
    die "Usage: $0 root\n";
}

@ARGV = ();

find(
    sub { 
	if ($_ eq 'testsuite' || (-d && /-share$/)) {
	    $File::Find::prune = 1;
	} elsif (-f && -T && /\.c$/ && $_ ne "gnu-regex.c") {
	    push @ARGV, $File::Find::name;
	}
    },
    $root
);

$INPLACE_EDIT = '';
undef $/;			# slurp entire files

while (<>) {
    s/\bfree \(/xfree (/g;
    s/\bmake_cleanup \(free,/make_cleanup (xfree,/g;
    s/\bfree\)/xfree)/g;
    print;
}
--- end subst-free-xfree ---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]