libxfs: fix krealloc to allow freeing data
PATCH 1/1 libxfs: fix krealloc to allow freeing data
From: Darrick J. Wong <[email protected]>
A recent refactoring to xfs_idata_realloc in the kernel made it depend on krealloc returning NULL if the new size is zero. The xfsprogs wrapper instead aborts, so we need to make it follow the kernel behavior.
Signed-off-by Darrick J. Wong <[email protected]>
--- libxfs/kmem.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
libxfs/kmem.c +10 -0
@@ -98,6 +98,16 @@ kmem_zalloc(size_t size, int flags)void *krealloc (void *ptr,size_t new_size,int flags) { +/* +* If @new_size is zero, Linux krealloc will free the memory and return +* NULL, so force that behavior here. The return value of realloc with +* a zero size is implementation dependent, so we cannot use that. +*/ +if (!new_size) { +free (ptr); +return NULL ; + } + ptr =realloc (ptr, new_size);if (ptr ==NULL ) { fprintf(stderr, _("%s: realloc failed (%d bytes): %s\n"),
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Quoted 8 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
A recent refactoring to
xfs_idata_reallocin the kernel made it depend on krealloc returning NULL if the new size is zero. The xfsprogs wrapper instead aborts, so we need to make it follow the kernel behavior.Signed-off-by Darrick J. Wong <[email protected]>
Reviewed-by Carlos Maiolino <[email protected]>
Quoted 25 lines
--- libxfs/kmem.c | 10 ++++++++++ 1 file changed, 10 insertions(+)libxfs/kmem.c +10
-0@@ -98,6 +98,16 @@ kmem_zalloc(size_t size, int flags)void *krealloc (void *ptr,size_t new_size,int flags) { +/* +* If @new_size is zero, Linux krealloc will free the memory and return +* NULL, so force that behavior here. The return value of realloc with +* a zero size is implementation dependent, so we cannot use that. +*/ +if (!new_size) { +free (ptr); +return NULL ; + } + ptr =realloc (ptr, new_size);if (ptr ==NULL ) { fprintf(stderr, _("%s: realloc failed (%d bytes): %s\n"),