[libvirt] [PATCH] BZ1072677: Avoid freeing of 0 file descriptor
Eric Blake
eblake at redhat.com
Mon Mar 10 21:49:54 UTC 2014
On 03/10/2014 01:10 PM, Stefan Berger wrote:
> Eric Blake <eblake at redhat.com> wrote on 03/10/2014 02:09:58 PM:
>
>>> +/* Initialize an array of file descriptors to -1 */
>>> +# define VIR_INIT_N_FD(ptr, count) \
>>> + vir_init_n_int(ptr, count, -1)
>>
>> Could also be spelled:
>>
>> memset(ptr, -1, sizeof(*ptr) * count))
>>
>> which goes back to why we need vir_init_n_int().
>
> Also this would be possible.
>
>>
>> I agree that the fix to qemu_hotplug.c to not close fd 0 on failure is
>> needed, but am not sure about the complexity of the virfile.h addition.
>>
>
> So a simple memset() would do? Having a macro for VIR_ALLOC_N_FD() would
> probably be too much, eh?
Indeed:
$ git grep memset.*1
src/conf/domain_conf.c: memset(max_idx, -1, sizeof(max_idx));
src/qemu/qemu_command.c: memset(tapfd, -1, tapfdSize *
sizeof(tapfd[0]));
src/qemu/qemu_command.c: memset(vhostfd, -1, vhostfdSize *
sizeof(vhostfd[0]));
So let's just copy that convention, instead of adding a new macro.
ACK to the qemu_hotplug fixes if you switch to raw memset.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140310/9811040b/attachment-0001.sig>
More information about the libvir-list
mailing list