From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvivx-0006g6-IY for qemu-devel@nongnu.org; Mon, 09 Nov 2015 04:40:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zvivt-00082G-HN for qemu-devel@nongnu.org; Mon, 09 Nov 2015 04:40:17 -0500 Received: from mx5-phx2.redhat.com ([209.132.183.37]:45785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvivt-00081z-9i for qemu-devel@nongnu.org; Mon, 09 Nov 2015 04:40:13 -0500 Date: Mon, 9 Nov 2015 04:40:09 -0500 (EST) From: Prasanna Kumar Kalever Message-ID: <2024052690.6797703.1447062009061.JavaMail.zimbra@redhat.com> In-Reply-To: <20151109070445.GF3391301@andariel.pipo.sk> References: <1446727026-18094-1-git-send-email-prasanna.kalever@redhat.com> <1446727026-18094-2-git-send-email-prasanna.kalever@redhat.com> <1677110309.4230186.1446727550535.JavaMail.zimbra@redhat.com> <20151109070445.GF3391301@andariel.pipo.sk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 3/3] block/gluster: add support for multiple gluster servers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Krempa Cc: kwolf@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org, deepakcs@redhat.com, bharata@linux.vnet.ibm.com, rtalur@redhat.com On Monday, November 9, 2015 12:34:45 PM, Peter Krempa wrote: > On Thu, Nov 05, 2015 at 07:45:50 -0500, Prasanna Kumar Kalever wrote: > > On Thursday, November 5, 2015 6:07:06 PM, Prasanna Kumar Kalever wrote: > > > This patch adds a way to specify multiple volfile servers to the gluster > > > block backend of QEMU with tcp|rdma transport types and their port > > > numbers. > > > > > > Problem: > > > > > > Currently VM Image on gluster volume is specified like this: > > > > [...] > > > > @@ -345,7 +676,7 @@ static int qemu_gluster_open(BlockDriverState *bs, > > > QDict > > > *options, > > > > > > out: > > > qemu_opts_del(opts); > > > - qemu_gluster_gconf_free(gconf); > > > + qapi_free_BlockdevOptionsGluster(gconf); > > > > Can some one help me please ? > > This leads to crash in the second iteration i.e. while freeing > > "gconf->servers->next->value" > > So, prior to this you allocate a array of the data structures as: > > + gsconf = g_new0(GlusterServer, num_servers); > + > + ptr = qemu_opt_get(opts, GLUSTER_OPT_VOLUME); > + if (!ptr) { > + error_setg(&local_err, "Error: qemu_gluster: please provide 'volume' > " > + "option"); > + goto out; > + } > > Then you use the following code to fill the linked list: > > + if (gconf->servers == NULL) { > + gconf->servers = g_new0(GlusterServerList, 1); > + gconf->servers->value = &gsconf[i]; > > So here you set the value. For a i of 0 the '&gsconf[i]' expression will > be a pointer with equal address to 'gsconf'. For explanation: > > 'gsconf[i]' can be written as '*(gsconf + i)', so > '&gsconf[i]' becomes basically '&(*(gsconf + i))' > > This can be also simplified to: > 'gsconf + i'. For a i of 0 this becomes the same pointer as 'gsconf' > > And once you use that with free(), the whole gsconf array will be freed. > All the other pointers that you've filled to the linked list become > invalid, since they were pointing into the same array that was > completely freed in the first iteration. Thanks for the help Peter, It solves the problem. -Prasanna > > Peter >