qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v6 08/47] Add qemu_get_buffer_less_copy to avoid


From: Amit Shah
Subject: Re: [Qemu-devel] [PATCH v6 08/47] Add qemu_get_buffer_less_copy to avoid copies some of the time
Date: Thu, 21 May 2015 14:28:06 +0530

On (Thu) 21 May 2015 [09:45:19], Dr. David Alan Gilbert wrote:
> * Amit Shah (address@hidden) wrote:

> > So we've got to assume that buf was allocated by the calling function,
> > and since we're modifying the pointer (alternative idea to one above),
> > should we unallocate it here?  Can lead to a bad g_free later, or a
> > memleak.
> 
> My use tends to involve a buffer allocated once:
> 
>         uint8_t *mybuffer = g_malloc(...)
> 
>         while (aloop) {
>             uint8_t *ourdata = mybuffer;
> 
>             if (qemu_get_buffer_less_copy(f, &ourdata, size)...) {
>                 do something with *ourdata
>             }
>   
>         }
>         g_free(mybuffer);
> 
> The pointer that's passed into qemu_get_buffer_less_copy is only a copy
> of the allocation pointer, and thus you're not losing anything when it
> changes it.
> 
> I've added the following text, does this make it clearer?
> 
>  * Note: Since **buf may get changed, the caller should take care to
>  *       keep a pointer to the original buffer if it needs to deallocate it.

Yes, thanks.

                Amit



reply via email to

[Prev in Thread] Current Thread [Next in Thread]