Skip to contentSkip to conversation

db/malloc: Use posix_memalign instead of deprecated valloc

PATCH In review Rosen Penev 3 participants 3 messages May 6, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 db/malloc: Use posix_memalign instead of deprecated valloc

valloc is not available with uClibc-ng as well as being deprecated, which causes compilation errors. aligned_alloc is not available before C11 so used posix_memalign.'

---
 db/malloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
db/malloc.c +1 -2
index 77b3e022..38fe0b05 100644
@@ -44,8 +44,7 @@ xmalloc(
 {
 	void	*ptr;
 
-	ptr = valloc(size);
-	if (ptr)
+	if(!posix_memalign(&ptr, sysconf(_SC_PAGESIZE), size))
 		return ptr;
 	badmalloc();
 	/* NOTREACHED */
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Rosen Penev

valloc is not available with uClibc-ng as well as being deprecated, which causes compilation errors. aligned_alloc is not available before C11 so used posix_memalign.'

---
 db/malloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
db/malloc.c +0 -0
index 77b3e022..38fe0b05 100644

db/malloc.c xmalloc( · line 47

Quoted 6 lines
db/malloc.c +1 -2
@@ -44,8 +44,7 @@ xmalloc(
 {
 	void	*ptr;
 
-	ptr = valloc(size);
-	if (ptr)
+	if(!posix_memalign(&ptr, sysconf(_SC_PAGESIZE), size))

I'll stick a space after the 'if' but otherwise, seems fine, thanks.

Quoted 4 lines
db/malloc.c +0 -0
 		return ptr;
 	badmalloc();
 	/* NOTREACHED */
#2 lore raw
Quoted 20 lines · Eric Sandeen
Quoted 17 lines · Rosen Penev

valloc is not available with uClibc-ng as well as being deprecated, which causes compilation errors. aligned_alloc is not available before C11 so used posix_memalign.'

---
 db/malloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
db/malloc.c +0 -0
index 77b3e022..38fe0b05 100644
@@ -44,8 +44,7 @@ xmalloc(
 {
 	void	*ptr;
 
Quoted 8 lines

db/malloc.c xmalloc( · line 47

Quoted 3 lines
db/malloc.c +1 -2
-	ptr = valloc(size);
-	if (ptr)
+	if(!posix_memalign(&ptr, sysconf(_SC_PAGESIZE), size))

I'll stick a space after the 'if' but otherwise, seems fine, thanks.

Can we just get rid of db/malloc.[ch]? They are just a set of wrappers that exit() when malloc fails, largely used by the deprecated xfs_check functionality we still have hidden inside xfs_db. Be a useful code self-documentation exercise to get rid of them to indicate that the callers don't actually handle malloc failures at all....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]