Source-Changes-HG archive

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

[src/netbsd-7]: src/sys/dev/dm Pull up following revision(s) (requested by ch...



details:   https://anonhg.NetBSD.org/src/rev/e822569fc3c3
branches:  netbsd-7
changeset: 798300:e822569fc3c3
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Aug 29 10:20:16 2014 +0000

description:
Pull up following revision(s) (requested by christos in ticket #55):
        sys/dev/dm/dm_target_stripe.c: revision 1.20-1.21
Avoid a memory leak - from maxv.
Cleanup properly on error.

diffstat:

 sys/dev/dm/dm_target_stripe.c |  45 ++++++++++++++++++++++++------------------
 1 files changed, 26 insertions(+), 19 deletions(-)

diffs (87 lines):

diff -r fb2fd2a0c2f1 -r e822569fc3c3 sys/dev/dm/dm_target_stripe.c
--- a/sys/dev/dm/dm_target_stripe.c     Wed Aug 27 15:30:45 2014 +0000
+++ b/sys/dev/dm/dm_target_stripe.c     Fri Aug 29 10:20:16 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.19.2.1 2014/08/29 10:20:16 martin Exp $*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -102,6 +102,23 @@
 }
 #endif
 
+static void
+dm_target_stripe_fini(dm_target_stripe_config_t *tsc)
+{
+       dm_target_linear_config_t *tlc;
+
+       if (tsc == NULL)
+               return;
+
+       while ((tlc = TAILQ_FIRST(&tsc->stripe_devs)) != NULL) {
+               TAILQ_REMOVE(&tsc->stripe_devs, tlc, entries);
+               dm_pdev_decr(tlc->pdev);
+               kmem_free(tlc, sizeof(*tlc));
+       }
+
+       kmem_free(tsc, sizeof(*tsc));
+}
+
 /*
  * Init function called from dm_table_load_ioctl.
  * DM_STRIPE_DEV_OFFSET should always hold the index of the first device-offset
@@ -156,8 +173,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(tlc, sizeof(*tlc));
+                       dm_target_stripe_fini(tsc);
                        return ENOENT;
+               }
                tlc->offset = atoi(argv[strpi+1]);
 
                /* Insert striping device to linked list. */
@@ -183,8 +203,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);
@@ -290,27 +312,12 @@
 int
 dm_target_stripe_destroy(dm_table_entry_t * table_en)
 {
-       dm_target_stripe_config_t *tsc;
-       dm_target_linear_config_t *tlc;
-
-       tsc = table_en->target_config;
-
-       if (tsc == NULL)
-               return 0;
-
-       while ((tlc = TAILQ_FIRST(&tsc->stripe_devs)) != NULL) {
-               TAILQ_REMOVE(&tsc->stripe_devs, tlc, entries);
-               dm_pdev_decr(tlc->pdev);
-               kmem_free(tlc, sizeof(*tlc));
-       }
+       dm_target_stripe_fini(table_en->target_config);
 
        /* Unbusy target so we can unload it */
        dm_target_unbusy(table_en->target);
 
-       kmem_free(tsc, sizeof(*tsc));
-
        table_en->target_config = NULL;
-
        return 0;
 }
 /* Doesn't not need to do anything here. */



Home | Main Index | Thread Index | Old Index