From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRhQk-0007DQ-J6 for qemu-devel@nongnu.org; Mon, 25 Jul 2016 11:04:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bRhQf-0000uY-Ts for qemu-devel@nongnu.org; Mon, 25 Jul 2016 11:04:29 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:55505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRhQd-0000rH-L2 for qemu-devel@nongnu.org; Mon, 25 Jul 2016 11:04:25 -0400 From: "Emilio G. Cota" Date: Mon, 25 Jul 2016 11:03:43 -0400 Message-Id: <1469459025-23606-2-git-send-email-cota@braap.org> In-Reply-To: <1469459025-23606-1-git-send-email-cota@braap.org> References: <1469459025-23606-1-git-send-email-cota@braap.org> Subject: [Qemu-devel] [PATCH 1/3] qdist: fix memory leak during binning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers Cc: Paolo Bonzini , Richard Henderson , Peter Maydell , Changlong Xie In qdist_bin__internal(), to->entries is initialized to a 1-element array, which we then leak when n == from->n. Fix it. Signed-off-by: Emilio G. Cota --- util/qdist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/qdist.c b/util/qdist.c index 56f5738..eb2236c 100644 --- a/util/qdist.c +++ b/util/qdist.c @@ -188,7 +188,7 @@ void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n) } } /* they're equally spaced, so copy the dist and bail out */ - to->entries = g_new(struct qdist_entry, from->n); + to->entries = g_realloc_n(to->entries, n, sizeof(*to->entries)); to->n = from->n; memcpy(to->entries, from->entries, sizeof(*to->entries) * to->n); return; -- 2.5.0