[Ocfs2-tools-devel] [PATCH 7/6] libocfs2: Catch memalign()s that will abort older glibcs. with description)
Joel Becker
Joel.Becker at oracle.com
Thu May 21 19:12:31 PDT 2009
[Caught this on the PPCs -- Joel ]
Older glibcs (before 2007/07, this includes the glibc in el5) would
abort if __libc_memalign() couldn't allocate the memory. That's
obviously a bogus behavior, but we have to handle it.
It's simple, though. We try with malloc() first. If that succeeds, we
know the memory is there and retry with posix_memalign().
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
libocfs2/memory.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/libocfs2/memory.c b/libocfs2/memory.c
index 589e114..a61fe42 100644
--- a/libocfs2/memory.c
+++ b/libocfs2/memory.c
@@ -102,9 +102,23 @@ errcode_t ocfs2_malloc_blocks(io_channel *channel, int num_blocks,
{
errcode_t ret;
int blksize;
+ size_t bytes;
void **pp = (void **)ptr;
+ void *tmp;
blksize = io_get_blksize(channel);
+ if (((unsigned long long)num_blocks * blksize) > SIZE_MAX)
+ return OCFS2_ET_NO_MEMORY;
+ bytes = num_blocks * blksize;
+
+ /*
+ * Older glibcs abort when they can't memalign() something.
+ * Ugh! Check with malloc() first.
+ */
+ tmp = malloc(bytes);
+ if (!tmp)
+ return OCFS2_ET_NO_MEMORY;
+ free(tmp);
ret = posix_memalign(pp, blksize, num_blocks * blksize);
if (!ret)
--
1.6.3
--
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
More information about the Ocfs2-tools-devel
mailing list