Skip to contentSkip to conversation

Fix memory leak in write_pool_threads

PATCH In review Eric Sesterhenn 3 participants 4 messages Jul 28, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix memory leak in write_pool_threads

hi,

kmemcheck produces the following warning

unreferenced object 0xc9ec02a0 (size 8):
comm "cat", pid 19048, jiffies 730243
backtrace:

    [<c01bf970>] create_object+0x100/0x240
    [<c01bfadb>] kmemleak_alloc+0x2b/0x60
    [<c01bcd4b>] __kmalloc+0x14b/0x270
    [<c02fd027>] write_pool_threads+0x87/0x1d0
    [<c02fcc08>] nfsctl_transaction_write+0x58/0x70
    [<c02fcc6f>] nfsctl_transaction_read+0x4f/0x60
    [<c01c2574>] vfs_read+0x94/0x150
    [<c01c297d>] sys_read+0x3d/0x70
    [<c0102d6b>] sysenter_do_call+0x12/0x32
    [<ffffffff>] 0xffffffff

write_pool_threads() only frees nthreads on error paths, in the success case we leak it.

fs/nfsd/nfsctl.c renamed from fs/nfsd/nfsctl.c.orig +1 -0
@@ -784,6 +784,7 @@ static ssize_t write_pool_threads(struct
 		mesg += len;
 	}
 
+	kfree(nthreads);
 	mutex_unlock(&nfsd_mutex);
 	return (mesg-buf);
 
#1 lore raw

2009/7/28 Eric Sesterhenn <eric.sesterhenn-9J169x0r4uIEe5DYm7f/[email protected]>:

Quoted 1 line

kmemcheck produces the following warning

That's "kmemleak" (a bit confusing since there is "kmemcheck" as well in the kernel :-)).

Quoted 14 lines

unreferenced object 0xc9ec02a0 (size 8):
=A0comm "cat", pid 19048, jiffies 730243 =A0backtrace:
=A0 =A0[<c01bf970>] create_object+0x100/0x240 =A0 =A0[<c01bfadb>] kmemleak_alloc+0x2b/0x60 =A0 =A0[<c01bcd4b>] __kmalloc+0x14b/0x270
=A0 =A0[<c02fd027>] write_pool_threads+0x87/0x1d0 =A0 =A0[<c02fcc08>] nfsctl_transaction_write+0x58/0x70 =A0 =A0[<c02fcc6f>] nfsctl_transaction_read+0x4f/0x60 =A0 =A0[<c01c2574>] vfs_read+0x94/0x150
=A0 =A0[<c01c297d>] sys_read+0x3d/0x70
=A0 =A0[<c0102d6b>] sysenter_do_call+0x12/0x32 =A0 =A0[<ffffffff>] 0xffffffff

Quoted 1 line

write_pool_threads() only frees nthreads on error paths, in the succe=

ss case

fs/nfsd/nfsctl.c =A0 =A0 =A02009-07-28 14:19:30.000000000 +=

Quoted 6 lines

we leak it.

fs/nfsd/nfsctl.c =A0 =A0 =A02009-07-28 14:19:30.000000000 += renamed from fs/nfsd/nfsctl.c.orig 2009-07-28 14:19:19.000000000 +0200 +0 -0

0200

fs/nfsd/nfsctl.c =A0 =A0 =A02009-07-28 14:19:30.000000000 += static ssize_t write_pool_threads(struct · line 789

Quoted 7 lines
fs/nfsd/nfsctl.c =A0 =A0 =A02009-07-28 14:19:30.000000000 += renamed from fs/nfsd/nfsctl.c.orig 2009-07-28 14:19:19.000000000 +0200 +1 -0
@@ -784,6 +784,7 @@ static ssize_t write_pool_threads(struct
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mesg +=3D len;
 =A0 =A0 =A0 =A0}
 
+ =A0 =A0 =A0 kfree(nthreads);
 =A0 =A0 =A0 =A0mutex_unlock(&nfsd_mutex);
 =A0 =A0 =A0 =A0return (mesg-buf);

Thanks for this. On minor point - the kfree() could probably be moved after mutex_unlock().

I added the patch to the kmemleak-fixes branch on
git://linux-arm.org/linux-2.6.git (I'm not pushing this branch upstream, it's mainly for people trying kmemleak to avoid reporting or investigating already fixed leaks).

--=20
Catalin

#4 lore raw
In reply to Eric Sesterhenn
Quoted 18 lines · Eric Sesterhenn

hi,

kmemcheck produces the following warning

unreferenced object 0xc9ec02a0 (size 8):
comm "cat", pid 19048, jiffies 730243
backtrace:

    [<c01bf970>] create_object+0x100/0x240
    [<c01bfadb>] kmemleak_alloc+0x2b/0x60
    [<c01bcd4b>] __kmalloc+0x14b/0x270
    [<c02fd027>] write_pool_threads+0x87/0x1d0
    [<c02fcc08>] nfsctl_transaction_write+0x58/0x70
    [<c02fcc6f>] nfsctl_transaction_read+0x4f/0x60
    [<c01c2574>] vfs_read+0x94/0x150
    [<c01c297d>] sys_read+0x3d/0x70
    [<c0102d6b>] sysenter_do_call+0x12/0x32
    [<ffffffff>] 0xffffffff
Quoted 2 lines

write_pool_threads() only frees nthreads on error paths, in the success case we leak it.

Thanks! Applied.

fs/nfsd/nfsctl.c static ssize_t write_pool_threads(struct · line 789

Quoted 11 lines
fs/nfsd/nfsctl.c renamed from fs/nfsd/nfsctl.c.orig +1 -0
@@ -784,6 +784,7 @@ static ssize_t write_pool_threads(struct
 		mesg += len;
 	}
 
+	kfree(nthreads);
 	mutex_unlock(&nfsd_mutex);
 	return (mesg-buf);

It also seems a little silly not to share the exit code here; applying the following on top.

--b.

commit 766dc4031548759efe4bd619715d3b5ffc2b53a5

Author: J. Bruce Fields <[email protected]>
Date:   Tue Jul 28 11:37:25 2009 -0400

nfsd: minor write_pool_threads exit cleanup

fs/nfsd/nfsctl.c +1 -5
index 48da164..b51e7ae 100644
@@ -784,11 +784,7 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
 		size -= len;
 		mesg += len;
 	}
-
-	kfree(nthreads);
-	mutex_unlock(&nfsd_mutex);
-	return (mesg-buf);
-
+	rv = mesg - buf;
 out_free:
 	kfree(nthreads);
 	mutex_unlock(&nfsd_mutex);
#3 lore raw
In reply to a message not in the archive
Quoted 5 lines · Catalin Marinas

2009/7/28 Eric Sesterhenn <eric.sesterhenn-9J169x0r4uIEe5DYm7f/[email protected]>:

Quoted 1 line

kmemcheck produces the following warning

=20
That's "kmemleak" (a bit confusing since there is "kmemcheck" as well in the kernel :-)).

Thanks, fixed up changelog and added a Reviewed-by: Catalin Marinas <[email protected]>.

--b.

Quoted 14 lines
Quoted 14 lines

unreferenced object 0xc9ec02a0 (size 8):
=C2=A0comm "cat", pid 19048, jiffies 730243 =C2=A0backtrace:
=C2=A0 =C2=A0[<c01bf970>] create_object+0x100/0x240 =C2=A0 =C2=A0[<c01bfadb>] kmemleak_alloc+0x2b/0x60 =C2=A0 =C2=A0[<c01bcd4b>] __kmalloc+0x14b/0x270 =C2=A0 =C2=A0[<c02fd027>] write_pool_threads+0x87/0x1d0 =C2=A0 =C2=A0[<c02fcc08>] nfsctl_transaction_write+0x58/0x70 =C2=A0 =C2=A0[<c02fcc6f>] nfsctl_transaction_read+0x4f/0x60 =C2=A0 =C2=A0[<c01c2574>] vfs_read+0x94/0x150 =C2=A0 =C2=A0[<c01c297d>] sys_read+0x3d/0x70 =C2=A0 =C2=A0[<c0102d6b>] sysenter_do_call+0x12/0x32 =C2=A0 =C2=A0[<ffffffff>] 0xffffffff

Quoted 1 line
Quoted 1 line

write_pool_threads() only frees nthreads on error paths, in the suc=

cess case

Quoted 6 lines

fs/nfsd/nfsctl.c =C2=A0 =C2=A0 =C2=A02009-07-28 14:19:30.=

Quoted 6 lines

we leak it.

fs/nfsd/nfsctl.c =C2=A0 =C2=A0 =C2=A02009-07-28 14:19:30.= renamed from fs/nfsd/nfsctl.c.orig 2009-07-28 14:19:19.000000000 +0200 +0 -0

000000000 +0200

Quoted 2 lines
Quoted 2 lines
fs/nfsd/nfsctl.c =C2=A0 =C2=A0 =C2=A02009-07-28 14:19:30.= renamed from fs/nfsd/nfsctl.c.orig 2009-07-28 14:19:19.000000000 +0200 +0 -0
@@ -784,6 +784,7 @@ static ssize_t write_pool_threads(struct

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mesg +=3D le=

n;

Quoted 5 lines
Quoted 5 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0}

+ =C2=A0 =C2=A0 =C2=A0 kfree(nthreads); =C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_unlock(&nfsd_mutex); =C2=A0 =C2=A0 =C2=A0 =C2=A0return (mesg-buf);

Quoted 7 lines

=20
Thanks for this. On minor point - the kfree() could probably be moved after mutex_unlock().
=20
I added the patch to the kmemleak-fixes branch on
git://linux-arm.org/linux-2.6.git (I'm not pushing this branch upstream, it's mainly for people trying kmemleak to avoid reporting o=

r

Quoted 6 lines

investigating already fixed leaks).
=20
--=20
Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" =

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html