[Libvir] [PATCH] Detect heap allocation failure; factor out some duplication.
Richard W.M. Jones
rjones at redhat.com
Wed Nov 28 16:16:08 UTC 2007
Daniel P. Berrange wrote:
> On Wed, Nov 28, 2007 at 02:18:22PM +0100, Jim Meyering wrote:
>> I spotted a few unchecked heap allocations (strdup, malloc, calloc)
>> in qemud.c and have fixed it so such failure evokes a proper diagnostic
>> rather than e.g., a segfault.
>
> Yep, good stuff.
>
>> I've also arranged to free some of the memory upon failure,
>> but not all (see comments for why).
>>
>> In spite of those additions, this patch factors out enough
>> duplication that the net change is to remove a few lines from the
>> file. Although in general I prefer to factor things out into
>> separate functions, in this case, it seemed better to use macros.
>
> I really don't like the macros, particularly when the macro definitions
> are inline to the function. I'd prefer to see these helpers as separate
> functions. The compiler is perfectly able to decide whether to inline
> the code or not & it makes it more friendly to edit & read when it is
> using separate functions.
The macros were my doing ... I'll leave it up to Jim's judgement as to
whether he wants to refactor them out into functions.
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20071128/e6431eef/attachment-0001.bin>
More information about the libvir-list
mailing list