Patchwork [3/4] page_cache: fix memory leak

login
register
mail settings
Submitter Orit Wasserman
Date Feb. 25, 2013, 1:19 p.m.
Message ID <1361798382-6515-4-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/222918/
State New
Headers show

Comments

Orit Wasserman - Feb. 25, 2013, 1:19 p.m.
From: Peter Lieven <pl@dlhnet.de>

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.

From: Peter Lieven <pl@kamp.de>

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 page_cache.c | 3 +++
 1 file changed, 3 insertions(+)

Patch

diff --git a/page_cache.c b/page_cache.c
index 21a4cde..07da547 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++;
     }