From 222b94805903dfa6879565ab9b1c8e3b0d70cbdf Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 2 Oct 2013 10:00:04 -0700 Subject: [PATCH] Fix memory leak false positive in log_internal() When building the spl with --enable-debug-kmem-tracking a memory leak is detected in log_internal(). This happens to be a false positive because the memory was freed using strfree() instead of kmem_free(). All kmem_alloc()'s must be released with kmem_free() to ensure correct accounting. SPL: kmem leaked 135/5641311 bytes address size data func:line ffff8800cba7cd80 135 ZZZZZZZZZZZZZZZZ log_internal:456 Signed-off-by: Brian Behlendorf --- module/zfs/spa_history.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module/zfs/spa_history.c b/module/zfs/spa_history.c index bbcd697e0..cb4816715 100644 --- a/module/zfs/spa_history.c +++ b/module/zfs/spa_history.c @@ -441,6 +441,7 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa, { char *msg; va_list adx1; + int size; /* * If this is part of creating a pool, not everything is @@ -453,13 +454,14 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa, } va_copy(adx1, adx); - msg = kmem_alloc(vsnprintf(NULL, 0, fmt, adx1) + 1, KM_PUSHPAGE); + size = vsnprintf(NULL, 0, fmt, adx1) + 1; + msg = kmem_alloc(size, KM_PUSHPAGE); va_end(adx1); va_copy(adx1, adx); (void) vsprintf(msg, fmt, adx1); va_end(adx1); fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg); - strfree(msg); + kmem_free(msg, size); fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation); fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg);