From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFr6-00084B-QO for qemu-devel@nongnu.org; Thu, 22 Jan 2015 06:23:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEFr3-0002Hx-Hd for qemu-devel@nongnu.org; Thu, 22 Jan 2015 06:23:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFr3-0002Hj-91 for qemu-devel@nongnu.org; Thu, 22 Jan 2015 06:23:17 -0500 Date: Thu, 22 Jan 2015 11:23:09 +0000 From: "Daniel P. Berrange" Message-ID: <20150122112309.GH16322@redhat.com> References: <1eb910dc8b31ac879c053006d7041f3edd6dd38d.1421768887.git.jcody@redhat.com> <20150122111735.GB28491@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150122111735.GB28491@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 2/6] block: vmdk - move string allocations from stack to the heap Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: kwolf@redhat.com, famz@redhat.com, Jeff Cody , qemu-devel@nongnu.org, stefanha@redhat.com, jsnow@redhat.com On Thu, Jan 22, 2015 at 11:17:35AM +0000, Stefan Hajnoczi wrote: > On Tue, Jan 20, 2015 at 12:31:29PM -0500, Jeff Cody wrote: > > @@ -792,12 +792,11 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > > const char *p = desc; > > int64_t sectors = 0; > > int64_t flat_offset; > > - char extent_path[PATH_MAX]; > > + char *extent_path = g_malloc0(PATH_MAX); > > Simpler alternative that has no risk of memory leaks: > > extent_path = g_malloc0(PATH_MAX); > path_combine(extent_path, sizeof(extent_path), > desc_file_path, fname); > extent_file = NULL; > ret = bdrv_open(&extent_file, extent_path, NULL, NULL, > bs->open_flags | BDRV_O_PROTOCOL, NULL, errp); > g_free(extent_path); Much better would be to change path_combine so it doesn't need to have the destination alloc done by the caller. Just have it allocate the right sized string buffer directly & return that and avoid the madness of PATH_MAX entirely. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|