Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/dm Avoid a memory leak - from maxv



details:   https://anonhg.NetBSD.org/src/rev/0deaa382d293
branches:  trunk
changeset: 331673:0deaa382d293
user:      agc <agc%NetBSD.org@localhost>
date:      Mon Aug 18 17:16:19 2014 +0000

description:
Avoid a memory leak - from maxv

diffstat:

 sys/dev/dm/dm_target_snapshot.c |   9 +++++----
 sys/dev/dm/dm_target_stripe.c   |  11 ++++++++---
 2 files changed, 13 insertions(+), 7 deletions(-)

diffs (65 lines):

diff -r 261b4e0ba38b -r 0deaa382d293 sys/dev/dm/dm_target_snapshot.c
--- a/sys/dev/dm/dm_target_snapshot.c   Mon Aug 18 16:55:34 2014 +0000
+++ b/sys/dev/dm/dm_target_snapshot.c   Mon Aug 18 17:16:19 2014 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target_snapshot.c,v 1.16 2014/06/14 07:39:00 hannken Exp $      */
+/*        $NetBSD: dm_target_snapshot.c,v 1.17 2014/08/18 17:16:19 agc Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -221,8 +221,7 @@
        if ((dmp_snap = dm_pdev_insert(argv[0])) == NULL)
                return ENOENT;
 
-       if ((tsc = kmem_alloc(sizeof(dm_target_snapshot_config_t), KM_NOSLEEP))
-           == NULL)
+       if ((tsc = kmem_alloc(sizeof(*tsc), KM_NOSLEEP)) == NULL)
                return 1;
 
        tsc->tsc_persistent_dev = 0;
@@ -232,8 +231,10 @@
                tsc->tsc_persistent_dev = 1;
 
                /* Insert cow device to global pdev list */
-               if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL)
+               if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL) {
+                       kmem_free(tsc, sizeof(*tsc));
                        return ENOENT;
+               }
        }
        tsc->tsc_chunk_size = atoi(argv[3]);
 
diff -r 261b4e0ba38b -r 0deaa382d293 sys/dev/dm/dm_target_stripe.c
--- a/sys/dev/dm/dm_target_stripe.c     Mon Aug 18 16:55:34 2014 +0000
+++ b/sys/dev/dm/dm_target_stripe.c     Mon Aug 18 17:16:19 2014 +0000
@@ -1,4 +1,4 @@
-/*$NetBSD: dm_target_stripe.c,v 1.19 2014/06/14 07:39:00 hannken Exp $*/
+/*$NetBSD: dm_target_stripe.c,v 1.20 2014/08/18 17:16:42 agc Exp $*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -156,8 +156,11 @@
                       argv[strpi], argv[strpi+1]);
 
                tlc = kmem_alloc(sizeof(*tlc), KM_NOSLEEP);
-               if ((tlc->pdev = dm_pdev_insert(argv[strpi])) == NULL)
+               if ((tlc->pdev = dm_pdev_insert(argv[strpi])) == NULL) {
+                       kmem_free(tsc, sizeof(*tsc));
+                       kmem_free(tlc, sizeof(*tlc));
                        return ENOENT;
+               }
                tlc->offset = atoi(argv[strpi+1]);
 
                /* Insert striping device to linked list. */
@@ -183,8 +186,10 @@
        if ((params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP)) == NULL)
                return NULL;
 
-       if ((tmp = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP)) == NULL)
+       if ((tmp = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP)) == NULL) {
+               kmem_free(params, DM_MAX_PARAMS_SIZE);
                return NULL;
+       }
 
        snprintf(params, DM_MAX_PARAMS_SIZE, "%d %" PRIu64,
            tsc->stripe_num, tsc->stripe_chunksize);



Home | Main Index | Thread Index | Old Index