From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7IvL-00023P-Mm for qemu-devel@nongnu.org; Tue, 23 Jun 2015 03:47:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7IvK-00085f-LE for qemu-devel@nongnu.org; Tue, 23 Jun 2015 03:47:15 -0400 Sender: Paolo Bonzini Message-ID: <55890EF8.4090608@redhat.com> Date: Tue, 23 Jun 2015 09:47:04 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1435021348-9156-1-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1435021348-9156-1-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] rdma: fix memory leak List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, amit.shah@redhat.com, mrhines@us.ibm.com, quintela@redhat.com On 23/06/2015 03:02, arei.gonglei@huawei.com wrote: > From: Gonglei > > Variable "r" going out of scope leaks the storage > it points to in line 3268. > > Signed-off-by: Gonglei > --- > migration/rdma.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/migration/rdma.c b/migration/rdma.c > index cf5de7e..de80860 100644 > --- a/migration/rdma.c > +++ b/migration/rdma.c > @@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = { > > static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode) > { > - QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA)); > + QEMUFileRDMA *r = NULL; No need for the NULL initialization. Paolo > > if (qemu_file_mode_is_not_valid(mode)) { > return NULL; > } > > + r = g_malloc0(sizeof(QEMUFileRDMA)); > r->rdma = rdma; > > if (mode[0] == 'w') { >