From 254e948b2908dd50df9dca4e6ed14b6cc8524fc9 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 29 Sep 2006 02:00:25 -0700 Subject: [PATCH] [PATCH] Fix memory leak in vc_resize/vc_allocate Memory leaks can happen in the vc_resize() function in drivers/char/vt.c because of the vc->vc_screenbuf variable overriding in vc_allocate(). The kmemleak reported trace is as follows: <__kmalloc> This patch no longer allocates a screen buffer in vc_allocate() if it was already allocated by vc_resize(). Signed-off-by: Catalin Marinas Acked-by: "Antonino A. Daplas" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/vt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/char/vt.c b/drivers/char/vt.c index b49f03375439..fb75da940b59 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -737,7 +737,8 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */ visual_init(vc, currcons, 1); if (!*vc->vc_uni_pagedir_loc) con_set_default_unimap(vc); - vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); + if (!vc->vc_kmalloced) + vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); if (!vc->vc_screenbuf) { kfree(vc); vc_cons[currcons].d = NULL; -- 2.20.1