On 4/22/19 9:17 PM, Eric Blake wrote:
> On 4/22/19 7:50 PM, Eric Blake wrote:
>> Time to enhance the nbd plugin to request structured replies from the
>> server. For now, deal only with structured reads. The server can now
>> return sparse reads, even though we need nbdkit version 3 before we
>> can in turn return sparse reads back to the client.
>>

>> +    if (rep.structured.length) {
>> +      /* Special case for OFFSET_DATA in order to read tail of chunk
>> +         directly into final buffer later on */
>> +      len = (rep.structured.type == NBD_REPLY_TYPE_OFFSET_DATA &&
>> +             rep.structured.length > sizeof offset) ? sizeof offset :
>> +        rep.structured.length;
>> +      buf = malloc (len);
> ...
> 
>> +    case NBD_REPLY_TYPE_OFFSET_DATA:
>> +      if (rep.structured.length <= sizeof offset) {
>> +        nbdkit_error ("structured reply OFFSET_DATA too small");
>> +        free (buf);
>> +        return nbd_mark_dead (h);
>> +      }
>> +      memcpy (&offset, buf, sizeof offset);
>> +      offset = be64toh (offset);
>> +      len = rep.structured.length - sizeof offset;
>> +      break;
> 
> leaks buf

These leaks would be a lot easier to avoid if we promote CLEANUP_FREE
out of server/internal.h into common/ for use by all filters and in-tree
plugins. Maybe I'll tackle that first (I've got it cleaned locally by
adding more free(buf) calls as appropriate, but without CLEANUP_FREE, it
gets even hairier when I also want to allocate something for .extents
handling that needs freeing in just as many places).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to