RE: [PATCH v2 1/3] make_corefile_notes: have caller free returned memory

Metzger, Markus T
2014-06-24T14:18:49Z

> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Tom Tromey
> Sent: Tuesday, June 24, 2014 3:45 PM
> To: Metzger, Markus T
> Cc: palves@redhat.com; gdb-patches@sourceware.org
> Subject: Re: [PATCH v2 1/3] make_corefile_notes: have caller free returned
> memory
>
> >>>>> "Markus" == Markus Metzger <markus.t.metzger@intel.com> writes:
>
> Markus> if (note_data == NULL || note_size == 0)
> Markus> error (_("Target does not support core file generation."));
>
> Markus> + cleanup = make_cleanup (xfree, note_data);
>
> I wonder if it is possible for note_data!=NULL but note_size==0.

I don't know. I have not found such a case, but that only means
that I have not looked hard enough.

I found a case where note_data == NULL but note_size could be > 0
in linux_spu_make_corefile_notes in linux-tdep.c, which is similarly
odd.

Other code in the same file is only checking note_data, not note_size.

> If it is possible, then the cleanup ought to be moved earlier.
> (FWIW it's ok to have an xfree cleanup with a NULL argument.)

I'll do that. Thanks for pointing out this bug.

> Or if it is not possible, then I suppose the code just above is in
> error... not your problem but if you happen to know, I would like to fix
> it up.

Replacing note_data and note_size with struct buffer would be nice,
but the change would be quite big, I'm afraid.

Regards,
Markus.
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052