[NETFILTER]: nfnetlink_log: fix instance_create() failure path
authorMichal Miroslaw <mirq-linux@rere.qmqm.pl>
Fri, 28 Sep 2007 21:45:27 +0000 (14:45 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Wed, 10 Oct 2007 23:53:39 +0000 (16:53 -0700)
Fix memory leak on instance_create() while module is being unloaded.

Signed-off-by: Michal Miroslaw <mirq-linux@rere.qmqm.pl>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netfilter/nfnetlink_log.c

index d2e811f4606798cfbe98c1cae52e25985085663e..16ae5391860641eb3be1bd16f4faa46f6ad125eb 100644 (file)
@@ -152,6 +152,11 @@ instance_create(u_int16_t group_num, int pid)
        if (!inst)
                goto out_unlock;
 
+       if (!try_module_get(THIS_MODULE)) {
+               kfree(inst);
+               goto out_unlock;
+       }
+
        INIT_HLIST_NODE(&inst->hlist);
        spin_lock_init(&inst->lock);
        /* needs to be two, since we _put() after creation */
@@ -168,9 +173,6 @@ instance_create(u_int16_t group_num, int pid)
        inst->copy_mode         = NFULNL_COPY_PACKET;
        inst->copy_range        = 0xffff;
 
-       if (!try_module_get(THIS_MODULE))
-               goto out_free;
-
        hlist_add_head(&inst->hlist,
                       &instance_table[instance_hashfn(group_num)]);
 
@@ -181,8 +183,6 @@ instance_create(u_int16_t group_num, int pid)
 
        return inst;
 
-out_free:
-       instance_put(inst);
 out_unlock:
        write_unlock_bh(&instances_lock);
        return NULL;