From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvMJI-0000W7-I8 for qemu-devel@nongnu.org; Thu, 21 May 2015 04:58:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YvMJE-0003wB-3V for qemu-devel@nongnu.org; Thu, 21 May 2015 04:58:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YvMJD-0003vl-Si for qemu-devel@nongnu.org; Thu, 21 May 2015 04:58:32 -0400 Date: Thu, 21 May 2015 14:28:06 +0530 From: Amit Shah Message-ID: <20150521085806.GN15452@grmbl.mre> References: <1429031053-4454-1-git-send-email-dgilbert@redhat.com> <1429031053-4454-9-git-send-email-dgilbert@redhat.com> <20150521070901.GM15452@grmbl.mre> <20150521084519.GC2129@work-vm> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150521084519.GC2129@work-vm> Subject: Re: [Qemu-devel] [PATCH v6 08/47] Add qemu_get_buffer_less_copy to avoid copies some of the time List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, quintela@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com, david@gibson.dropbear.id.au On (Thu) 21 May 2015 [09:45:19], Dr. David Alan Gilbert wrote: > * Amit Shah (amit.shah@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