Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Signed-off-by: Tim Chase <[email protected]> Signed-off-by: Chunwei Chen <[email protected]> Closes #2262
- Loading branch information
4fd762f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amusingly, this was causing some issues for us over in OSX. With our slice allocator, often it would allocate from size 16, truncate the string, then spa_strfree() would free it as shorter than 16, and be placed on the size 8 slice. The the memory would be in two slices, and be given out to two allocs simultaneously. Highly amusing. Strangely IllumOS uses kmem_alloc with
len
to allocate the string, but call spa_strfree (on the shorter string) even though they havelen
still. We had to go with properopenzfsonosx/zfs@b042140...e2eafee
but also add debug to our SPL slice allocator to throw a fit when alloc and free sizes do not agree, so we can find these situations much more quickly.
4fd762f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this has been a problem in to past as well. I've wondered if we shouldn't just blacklist strdup() and strfree() so they never used. Sadly a a fair bit of code uses them...
4fd762f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with @lundman in his update for osx - i have panic on dilos with current changes too
moved to @lundman version solved panic