On (Thu) 21 May 2015 [09:45:19], Dr. David Alan Gilbert wrote:
> * Amit Shah (amit.s...@redhat.com) 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