netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: maximilian attems <janitor@sternwelten.at>
To: netdev@oss.sgi.com
Subject: [patch-kj]  net/ipv4/fib_hash.c: check kmem_cache_create()
Date: Mon, 21 Jun 2004 19:18:32 +0200	[thread overview]
Message-ID: <20040621171832.GE1545@sputnik.stro.at> (raw)




From: Francois Romieu <romieu@fr.zoreil.com>

kmem_cache_create leak.

Note: fib_hash_init() can be called many times.

Signed-off-by: Maximilian Attems <janitor@sternwelten.at>



---

 linux-2.6.7-max/net/ipv4/fib_hash.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff -puN net/ipv4/fib_hash.c~ipv4_fib_hash_check net/ipv4/fib_hash.c
--- linux-2.6.7/net/ipv4/fib_hash.c~ipv4_fib_hash_check	2004-06-18 09:10:27.000000000 +0200
+++ linux-2.6.7-max/net/ipv4/fib_hash.c	2004-06-18 09:10:27.000000000 +0200
@@ -871,15 +871,18 @@ struct fib_table * __init fib_hash_init(
 {
 	struct fib_table *tb;
 
-	if (fn_hash_kmem == NULL)
+	tb = kmalloc(sizeof(struct fib_table) + sizeof(struct fn_hash), GFP_KERNEL);
+	if (!tb)
+		goto err_out;
+
+	if (!fn_hash_kmem) {
 		fn_hash_kmem = kmem_cache_create("ip_fib_hash",
 						 sizeof(struct fib_node),
 						 0, SLAB_HWCACHE_ALIGN,
 						 NULL, NULL);
-
-	tb = kmalloc(sizeof(struct fib_table) + sizeof(struct fn_hash), GFP_KERNEL);
-	if (tb == NULL)
-		return NULL;
+		if (!fn_hash_kmem)
+			goto err_free;
+	}
 
 	tb->tb_id = id;
 	tb->tb_lookup = fn_hash_lookup;
@@ -889,7 +892,13 @@ struct fib_table * __init fib_hash_init(
 	tb->tb_select_default = fn_hash_select_default;
 	tb->tb_dump = fn_hash_dump;
 	memset(tb->tb_data, 0, sizeof(struct fn_hash));
+err_out:
 	return tb;
+
+err_free:
+	kfree(tb);
+	tb = NULL;
+	goto err_out;
 }
 
 /* ------------------------------------------------------------------------ */

_

             reply	other threads:[~2004-06-21 17:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-21 17:18 maximilian attems [this message]
2004-06-21 18:21 ` [patch-kj] net/ipv4/fib_hash.c: check kmem_cache_create() YOSHIFUJI Hideaki / 吉藤英明
2004-06-21 20:04   ` maximilian attems
2004-06-21 23:51     ` YOSHIFUJI Hideaki / 吉藤英明
  -- strict thread matches above, loose matches on Subject: below --
2004-06-21 23:52 Krishna Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040621171832.GE1545@sputnik.stro.at \
    --to=janitor@sternwelten.at \
    --cc=netdev@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).