[Ocfs2-tools-devel] [PATCH 01/13] libocfs2: Catch memalign()s that will abort older glibcs.
Joel Becker
joel.becker at oracle.com
Tue May 26 16:03:21 PDT 2009
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
More information about the Ocfs2-tools-devel
mailing list