From: Emilio G. Cota Date: Mon, 25 Jul 2016 15:03:43 +0000 (-0400) Subject: qdist: fix memory leak during binning X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=f9dbc19e8bf58d0cbc830083352475bb16f315c4;p=qemu.git qdist: fix memory leak during binning 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 Message-Id: <1469459025-23606-2-git-send-email-cota@braap.org> Signed-off-by: Paolo Bonzini --- diff --git a/util/qdist.c b/util/qdist.c index 56f573837d..eb2236cdc8 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;