arch_init.c: Free 'cache' in cache_fini() to avoid memory leak
Call g_free() after cache_fini() in migration_end(), but do not call g_free() after call cache_fini() in xbzrle_cache_resize() which will cause memory leak.
cache_init() and cache_fini() are pair, so need let cache_fini() call g_free(cache) to match cache_init(), then fix current issue too.
--- arch_init.c | 1 - page_cache.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
arch_init.c +0 -1
@@ -739,7 +739,6 @@ static void migration_end(void)XBZRLE_cache_lock ();if (XBZRLE .cache) {cache_fini (XBZRLE .cache); -g_free (XBZRLE .cache);g_free (XBZRLE .encoded_buf);g_free (XBZRLE .current_buf);XBZRLE .cache =NULL ;
page_cache.c +1 -0
@@ -109,6 +109,7 @@ void cache_fini(PageCache *cache)g_free (cache->page_cache); cache->page_cache =NULL ; +g_free (cache); } static size_t cache_get_cache_pos(const PageCache *cache,
Signature · 1 line
1.7.11.7
ChenLiang
Reviewed-byQuoted 31 lines · Chen Gang
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.Signed-off-by Chen Gang <[email protected]>--- arch_init.c | 1 - page_cache.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)arch_init.c +0
-1@@ -739,7 +739,6 @@ static void migration_end(void)XBZRLE_cache_lock ();if (XBZRLE .cache) {cache_fini (XBZRLE .cache); -g_free (XBZRLE .cache);g_free (XBZRLE .encoded_buf);g_free (XBZRLE .current_buf);XBZRLE .cache =NULL ;page_cache.c +0
-0
page_cache.c void cache_fini(PageCache *cache) · line 115
Quoted 7 lines
page_cache.c +1
-0@@ -109,6 +109,7 @@ void cache_fini(PageCache *cache)g_free (cache->page_cache); cache->page_cache =NULL ; +g_free (cache); } static size_t cache_get_cache_pos(const PageCache *cache,
Quoted 6 lines · Chen Gang
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.
I'm not sure I get you. Is the following accurate?
migration: Plug memory leak in migrate-set-cache-size command
We call g_free() after cache_fini() in migration_end(), but we don't call it after cache_fini() in xbzrle_cache_resize(), leaking the memory.
cache_init() and cache_fini() are a pair. Since cache_init() allocates the cache, let cache_fini() free it. This plugs the leak.
Quoted 11 lines · Markus Armbruster
Quoted 6 lines · Chen Gang
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.I'm not sure I get you. Is the following accurate?
Quoted 9 lines
migration: Plug memory leak in migrate-set-cache-size command
We call
g_free()aftercache_fini()inmigration_end(), but we don't call it aftercache_fini()inxbzrle_cache_resize(), leaking the memory.
cache_init()andcache_fini()are a pair. Sincecache_init()allocates the cache, letcache_fini()free it. This plugs the leak.
Yeah, and excuse me for my poor English.
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Quoted 18 lines · Chen Gang
Quoted 17 lines · Markus Armbruster
Quoted 6 lines · Chen Gang
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.I'm not sure I get you. Is the following accurate?
migration: Plug memory leak in migrate-set-cache-size command
We call
g_free()aftercache_fini()inmigration_end(), but we don't call it aftercache_fini()inxbzrle_cache_resize(), leaking the memory.
Quoted 5 lines
Quoted 3 lines
cache_init()andcache_fini()are a pair. Sincecache_init()allocates the cache, letcache_fini()free it. This plugs the leak.Yeah, and excuse me for my poor English.
No problem, we figured it out together :)
Would be nice to use the above text as commit message. Perhaps it can be done on commit.
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Chen Gang
Quoted 20 lines · Markus Armbruster
Quoted 6 lines · Chen Gang
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.I'm not sure I get you. Is the following accurate?
migration: Plug memory leak in migrate-set-cache-size command
We call
g_free()aftercache_fini()inmigration_end(), but we don't call it aftercache_fini()inxbzrle_cache_resize(), leaking the memory.
cache_init()andcache_fini()are a pair. Sincecache_init()allocates the cache, letcache_fini()free it. This plugs the leak.
Quoted 7 lines
Quoted 1 line
Yeah, and excuse me for my poor English.
No problem, we figured it out together :)
Would be nice to use the above text as commit message. Perhaps it can be done on commit.
That is fine to me.
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Dr. David Alan Gilbert
Reviewed-byQuoted 9 lines · * Chen Gang ([email protected]) wrote:
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.Signed-off-by Chen Gang <[email protected]>
Yes, good catch.
Quoted 32 lines
--- arch_init.c | 1 - page_cache.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)arch_init.c +0
-1@@ -739,7 +739,6 @@ static void migration_end(void)XBZRLE_cache_lock ();if (XBZRLE .cache) {cache_fini (XBZRLE .cache); -g_free (XBZRLE .cache);g_free (XBZRLE .encoded_buf);g_free (XBZRLE .current_buf);XBZRLE .cache =NULL ;page_cache.c +1
-0@@ -109,6 +109,7 @@ void cache_fini(PageCache *cache)g_free (cache->page_cache); cache->page_cache =NULL ; +g_free (cache); } static size_t cache_get_cache_pos(const PageCache *cache,Signature · 1 line
1.7.11.7
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Michael Tokarev
AppliedQuoted 6 lines · Chen Gang
Call
g_free()aftercache_fini()inmigration_end(), but do not callg_free()after callcache_fini()inxbzrle_cache_resize()which will cause memory leak.
cache_init()andcache_fini()are pair, so need letcache_fini()callg_free(cache)to matchcache_init(), then fix current issue too.
Applied to -trivial, with the following commit message:
migration: Plug memory leak in migrate-set-cache-size command
We call g_free() after cache_fini() in migration_end(), but we don't call it after cache_fini() in xbzrle_cache_resize(), leaking the memory.
cache_init() and cache_fini() are a pair. Since cache_init() allocates the cache, let cache_fini() free it. This plugs the leak.
Thanks,
/mjt