]> git.hungrycats.org Git - linux/commitdiff
[PATCH] Fix memleak on execve failure
authorAndrew Morton <akpm@osdl.org>
Tue, 30 Dec 2003 07:46:31 +0000 (23:46 -0800)
committerLinus Torvalds <torvalds@home.osdl.org>
Tue, 30 Dec 2003 07:46:31 +0000 (23:46 -0800)
From: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>

I found linux-2.6.0-test11 leaks memory when execve fails.  I've also
checked the bitkeeper tree and the problem seems to be unchanged.

The attached patch is a partial backout of bitkeeper rev.  1.87 of
fs/exec.c.  I guess the original change was a simple mistake.
(free_arg_pages() is a NOP when CONFIG_MMU is defined).

fs/exec.c

index 34c5697d1a3b641b63b9c4b3330f87177887f88d..a0e769adec78cce61d5439efcc37b07aa6726945 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1085,6 +1085,7 @@ int do_execve(char * filename,
        struct linux_binprm bprm;
        struct file *file;
        int retval;
+       int i;
 
        sched_balance_exec();
 
@@ -1153,7 +1154,11 @@ int do_execve(char * filename,
 
 out:
        /* Something went wrong, return the inode and free the argument pages*/
-       free_arg_pages(&bprm);
+       for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
+               struct page * page = bprm.page[i];
+               if (page)
+                       __free_page(page);
+       }
 
        if (bprm.security)
                security_bprm_free(&bprm);