From 4fd762f8ad59f5840c790357a0e50f15cc9ccc08 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 17 Apr 2014 10:06:37 -0700 Subject: Fix zfsdev_ioctl() kmem leak warning Due to an asymmetry in the kmem accounting a memory leak was being reported when it was only an accounting issue. All memory allocated with kmem_alloc() must be released with kmem_free() or it will not be properly accounted for. In this case the code used strfree() to release the memory allocated by kmem_alloc(). Presumably this was done because the size of the memory region wasn't available when the memory needed to be freed. To resolve this issue the code has been updated to use strdup() instead of kmem_alloc() to allocate the memory. Like strfree(), strdup() is not integrated with the memory accounting. This means we can use strfree() to release it like Illumos. SPL: kmem leaked 10/4368729 bytes address size data func:line ffff880067e9aa40 10 ZZZZZZZZZZ zfsdev_ioctl:5655 Signed-off-by: Brian Behlendorf Signed-off-by: Tim Chase Signed-off-by: Chunwei Chen Closes #2262 --- module/zfs/zfs_ioctl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'module/zfs') diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index 0dfda1abf..5f97ea454 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -5584,7 +5584,7 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg) { zfs_cmd_t *zc; uint_t vecnum; - int error, rc, len = 0, flag = 0; + int error, rc, flag = 0; const zfs_ioc_vec_t *vec; char *saved_poolname = NULL; nvlist_t *innvl = NULL; @@ -5651,9 +5651,13 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg) goto out; /* legacy ioctls can modify zc_name */ - len = strcspn(zc->zc_name, "/@#") + 1; - saved_poolname = kmem_alloc(len, KM_SLEEP); - (void) strlcpy(saved_poolname, zc->zc_name, len); + saved_poolname = strdup(zc->zc_name); + if (saved_poolname == NULL) { + error = SET_ERROR(ENOMEM); + goto out; + } else { + saved_poolname[strcspn(saved_poolname, "/@#")] = '\0'; + } if (vec->zvec_func != NULL) { nvlist_t *outnvl; @@ -5721,7 +5725,7 @@ out: (void) tsd_set(zfs_allow_log_key, saved_poolname); } else { if (saved_poolname != NULL) - kmem_free(saved_poolname, len); + strfree(saved_poolname); } kmem_free(zc, sizeof (zfs_cmd_t)); -- cgit v1.2.3