evilsong / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

debugallocation realloc fails with memalign #464

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Realloc'ing a block of memory allocated by memalign() appears to be broken. I 
believe the offset isn't being stored correctly, and the realloc'd memory 
doesn't have the correct data.

The below program should reproduce the issue.
Thanks!

// mikesart@gmail.com or mikesart@valvesoftware.com
//
// gcc -Wall blah.c -o blah
// 
// mikesart@mikesart-linux:~/blah$ gcc -Wall blah.c -o blah
// mikesart@mikesart-linux:~/blah$ ./blah
// memalign: 
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111
// realloc:  
11111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111110000000000
// mikesart@mikesart-linux:~/blah$ 
LD_PRELOAD=/home/mikesart/valvesrc/gperftools-2.0/linux32/lib/libtcmalloc_debug.
so ./blah
// memalign: 
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111
// realloc:  
abababab10000abababababababab111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111

// mikesart@mikesart-linux:~/blah$ lsb_release -a
// No LSB modules are available.
// Distributor ID: Ubuntu
// Description:    Ubuntu 12.04.1 LTS
// Release:        12.04
// Codename:       precise
//
// 32-bit, if that matters.

#include <stdio.h>
#include <malloc.h>
#include <string.h>

#define SIZE_ALLOC      50
#define SIZE_REALLOC    60

void dump_memory( void *p, size_t size )
{
    size_t i;
    unsigned char *pch = ( unsigned char * )p;

    for( i = 0; i < size; i++ )
    {
        printf( "%x", pch[ i ] );
    }
    printf( "\n" );
}

int main( int argc, char **argv )
{
    void *p;

    printf( "memalign: " );
    p = memalign( 16, SIZE_ALLOC );
    memset( p, 0x11, SIZE_ALLOC );
    dump_memory( p, SIZE_ALLOC );

    printf( "realloc:  " );
    p = realloc( p, SIZE_REALLOC );
    dump_memory( p, SIZE_REALLOC );

    return 0;
}

Original issue reported on code.google.com by mikes...@gmail.com on 7 Sep 2012 at 4:41

GoogleCodeExporter commented 9 years ago

Original comment by chapp...@gmail.com on 3 Nov 2012 at 4:48

GoogleCodeExporter commented 9 years ago
Please see b/1397952 (Google-only) for more info how this has been handled 
Google-side.

Original comment by phaj...@google.com on 28 Jan 2013 at 11:21

GoogleCodeExporter commented 9 years ago

Original comment by alkondratenko on 30 Aug 2013 at 2:59

GoogleCodeExporter commented 9 years ago
Proposed fix is uploaded here: 
https://github.com/alk/gperftools/commit/f45c7c3dffff58c449ac7b15242e72f190c223c
a

(https://github.com/alk/gperftools/commits/issue-464)

Consider reviewing or testing it please

Original comment by alkondratenko on 17 Feb 2014 at 4:06

GoogleCodeExporter commented 9 years ago
Fix is now merged

Original comment by alkondratenko on 22 Feb 2014 at 8:19