Bug 301229

Summary: posix_memalign fails for 2MB alignment
Product: [Developer tools] valgrind Reporter: Bradley C. Kuszmaul <kuszmaul>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED DUPLICATE    
Severity: crash CC: benh, philippe.waroquiers
Priority: NOR    
Version First Reported In: 3.7.0   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Bradley C. Kuszmaul 2012-06-05 16:26:15 UTC
This may be a duplicate of https://bugs.kde.org/show_bug.cgi?id=203877, which complains about memalign.  This complaint is about posix_memalign.

This program:

#include <assert.h>
#include <stdlib.h>

int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
    void *p;
    int r = posix_memalign(&p, 2*1024*1024, 2*1024*1024);
    assert(r==0);
    free(p);
    return 0;
}

Gives this failure on valgrind:

$ /home/bradley/valgrind/bin/valgrind ./malign
==9457== Memcheck, a memory error detector
==9457== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==9457== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==9457== Command: ./malign
==9457== 
VG_(arena_memalign)(0x388DC258, 2097152, 2097152)
bad alignment value 2097152
(it is too small, too big, or not a power of two)
valgrind: the 'impossible' happened:
   VG_(arena_memalign)
==9457==    at 0x3804D206: report_and_quit (m_libcassert.c:210)
==9457==    by 0x3804D263: panic (m_libcassert.c:294)
==9457==    by 0x3804D418: vgPlain_core_panic_at (m_libcassert.c:299)
==9457==    by 0x3804D42A: vgPlain_core_panic (m_libcassert.c:304)
==9457==    by 0x38059B2B: vgPlain_arena_memalign (m_mallocfree.c:1870)
==9457==    by 0x38021AFC: vgMemCheck_new_block (mc_malloc_wrappers.c:248)
==9457==    by 0x38021DAF: vgMemCheck_memalign (mc_malloc_wrappers.c:315)
==9457==    by 0x38090402: vgPlain_scheduler (scheduler.c:1469)
==9457==    by 0x3809FDD5: run_a_thread_NORETURN (syswrap-linux.c:98)

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable
==9457==    at 0x4A05BB2: memalign (vg_replace_malloc.c:694)
==9457==    by 0x4A05C0B: posix_memalign (vg_replace_malloc.c:835)
==9457==    by 0x400588: main (in /home/bradley/malign)
Comment 1 Benjamin Herrenschmidt 2012-06-09 23:47:15 UTC
Same problem with 16M (probably a dup of #203877 indeed, I was using posix_memalign as well
Comment 2 Philippe Waroquiers 2012-06-15 22:22:34 UTC

*** This bug has been marked as a duplicate of bug 203877 ***