From patchwork Mon Feb 25 12:44:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 222915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A578C2C02C2 for ; Mon, 25 Feb 2013 23:44:16 +1100 (EST) Received: from localhost ([::1]:33936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9xPi-0002tn-TU for incoming@patchwork.ozlabs.org; Mon, 25 Feb 2013 07:44:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9xPY-0002tS-Ql for qemu-devel@nongnu.org; Mon, 25 Feb 2013 07:44:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9xPV-0006py-Cz for qemu-devel@nongnu.org; Mon, 25 Feb 2013 07:44:04 -0500 Received: from ssl.dlhnet.de ([91.198.192.8]:53116 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9xPV-0006pl-7I for qemu-devel@nongnu.org; Mon, 25 Feb 2013 07:44:01 -0500 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 3500E14DAEE; Mon, 25 Feb 2013 13:44:00 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OYtR+7Gw7GO8; Mon, 25 Feb 2013 13:43:59 +0100 (CET) Received: from [172.21.12.60] (unknown [82.141.1.226]) by ssl.dlh.net (Postfix) with ESMTPSA id D061814D8BD; Mon, 25 Feb 2013 13:43:59 +0100 (CET) Message-ID: <512B5C90.6040807@dlhnet.de> Date: Mon, 25 Feb 2013 13:44:00 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" , Orit Wasserman , peter.maydell@linaro.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Subject: [Qemu-devel] [PATCHv2] page_cache: fix memory leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org XBZRLE encoded migration introduced a MRU page cache meachnism. Unfortunately, cached items where never freed in case of a collision in the page cache on cache_insert(). This lead to out of memory conditions during XBZRLE migration if the page cache was small and there where a lot of collisions in the cache. Signed-off-by: Peter Lieven --- v2: - make g_free unconditional. page_cache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/page_cache.c b/page_cache.c index ba5640b..376f1db 100644 --- a/page_cache.c +++ b/page_cache.c @@ -152,6 +152,9 @@ void cache_insert(PageCache *cache, uint64_t addr, uint8_t *pdata) /* actual update of entry */ it = cache_get_by_addr(cache, addr); + /* free old cached data if any */ + g_free(it->it_data); + if (!it->it_data) { cache->num_items++; }