malloc rare error (malloc bug??)

J

JPerelli

Hello

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:

*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
../7sd32[0x804b3be]
../7sd32[0x804b7aa]
../7sd32[0x804b820]
../7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
../7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809 /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809 /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809 /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0 [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288 /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288 /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288 /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288 /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302 /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302 /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302 /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910 /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910 /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910 /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0 [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285 /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285 /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285 /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0 [stack]
Cancelado


I googled a lot, but can't find anything that guides me...

also I make some debugging in gdb:


Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0 0xf7f14425 in __kernel_vsyscall ()
#1 0xf7da09a0 in raise () from /lib32/libc.so.6
#2 0xf7da2368 in abort () from /lib32/libc.so.6
#3 0xf7ddee4d in ?? () from /lib32/libc.so.6
#4 0xf7de5204 in ?? () from /lib32/libc.so.6
#5 0xf7de81e6 in ?? () from /lib32/libc.so.6
#6 0xf7de95f5 in malloc () from /lib32/libc.so.6
#7 0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8 0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9 0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7 0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41 binario = malloc(sizeof(int)*8); <----- call that causes error
(gdb) frame 6
#6 0xf7de95f5 in malloc () from /lib32/libc.so.6


so the program lines close to the error are this:

int *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);

it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??

thank you in advance

Julian
 
M

Mark Bluemel

Hello

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:

*** glibc detected *** ./7sd32: malloc(): memory corruption: ....

so the program lines close to the error are this:

int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);

it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??

You're (almost certainly) abusing some memory allocated with malloc -
buffer overwrite or something similar. This is corrupting the internal
structures used by malloc to manage its space.

The problem can't be detected until malloc (or one of the malloc/free
family) is next called, so that's when you get your error. This is not
where the corruption occured.

This page may help you - <http://www.gnu.org/s/libc/manual/html_node/
Heap-Consistency-Checking.html> - especially the MALLOC_CHECK_
discussion. Otherwise there are tools such as "Electric Fence" <http://
directory.fsf.org/project/ElectricFence/> which should help you.
 
D

David RF

Hello

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:

*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado

I googled a lot, but can't find anything that guides me...

also I make some debugging in gdb:

Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6

so the program lines close to the error are this:

int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);

it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??

thank you in advance

Julian

I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);

Spanish P.D: Memory corruption es tan ambiguo como decir, toma hostia
¿quien ha sido? ... insisto en valgrind
 
D

David RF

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:
*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado
I googled a lot, but can't find anything that guides me...
also I make some debugging in gdb:
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
so the program lines close to the error are this:
int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);
it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??
thank you in advance

I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);

Spanish P.D: Memory corruption es tan ambiguo como decir, toma hostia
¿quien ha sido? ... insisto en valgrind

ops,
/home/jperelli/Escritorio/7sd/
.... there is no valgrind for Windows, you can try DUMA:
http://duma.sourceforge.net/
 
M

Mug

Hello

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:

*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado

I googled a lot, but can't find anything that guides me...

also I make some debugging in gdb:

Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6

so the program lines close to the error are this:

int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);

it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??

thank you in advance

Julian

hello, in my experience(i had once the similar problem), i can just
guess,it might be problem of your usage of variable binario.
by exemple ,if u fill the binario more than sizeof(int)*8, and u
return the binario at the end of fonction. then u call the fonction
outside of this file, u try to read the content of the allocated
memory region, it can cause this problem.
it's just a guess, try to track down where did u use the variable
binario.
 
M

Mark Bluemel

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:
*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado
I googled a lot, but can't find anything that guides me...
also I make some debugging in gdb:
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
so the program lines close to the error are this:
int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);
it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??
thank you in advance

hello, in my experience(i had once the similar problem), i can just
guess,it might be problem of your usage of variable binario.

Or any other pointer to dynamically allocated memory.

The important thing to note with crashes in malloc() family functions
is that they are often caused by something other than the code at the
point of failure.
by exemple ,if u fill the binario more than sizeof(int)*8, and u
return the binario at the end of fonction. then u call the fonction
outside of this file,  u try to read the content of the allocated
memory region, it can cause this problem.
it's just a guess, try to track down where did u use the variable
binario.

It's probably not that helpful to focus on binario, unless it is the
only pointer to dynamically allocated memory.
 
J

JPerelli

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:
*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado
I googled a lot, but can't find anything that guides me...
also I make some debugging in gdb:
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
so the program lines close to the error are this:
int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);
it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??
thank you in advance

I see no errors in your code, use valgrind for more details and ...

sorry, I did used valgrind for the 32 bit version on my 64 bits
machine, and I get no errors.
Again, the program works good in 64bit, so I think that valgrind
executes the program in some type of environment that makes the error
dissapear (something with 32/64bits environment emulation).
Maybe I have to get a 32bits box where i can run valgrind... so all is
32bits
I'll try that
 
J

JPerelli

Hello
I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:
*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado
I googled a lot, but can't find anything that guides me...
also I make some debugging in gdb:
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
so the program lines close to the error are this:
int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);
it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??
thank you in advance
Julian
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);
Spanish P.D: Memory corruption es tan ambiguo como decir, toma hostia
¿quien ha sido? ... insisto en valgrind

ops,
/home/jperelli/Escritorio/7sd/

That sile structure is Linux, I use valgrind, thanks!
 
J

JPerelli

I'd like to make a program for a 32bit architecture, but I have some
problem that I can't figure how to resolve
The program compiles and works great under 64 bits, but in 32 bits
throws this runtime error:
*** glibc detected *** ./7sd32: malloc(): memory corruption:
0x09cb6160 ***
======= Backtrace: =========
/lib32/libc.so.6[0xf7ea1ea6]
/lib32/libc.so.6(__libc_malloc+0x95)[0xf7ea35f5]
./7sd32[0x804b3be]
./7sd32[0x804b7aa]
./7sd32[0x804b820]
./7sd32[0x804c387]
/lib32/libc.so.6(__libc_start_main+0xe5)[0xf7e45775]
./7sd32[0x80493a1]
======= Memory map: ========
08048000-0804e000 r-xp 00000000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804e000-0804f000 r--p 00005000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
0804f000-08050000 rw-p 00006000 08:01
6448809                            /home/jperelli/Escritorio/7sd/
julian/daemon/7sd32
09cb6000-09cd7000 rw-p 09cb6000 00:00
0                                  [heap]
f7500000-f7521000 rw-p f7500000 00:00 0
f7521000-f7600000 ---p f7521000 00:00 0
f762c000-f762d000 ---p f762c000 00:00 0
f762d000-f7e2f000 rw-p f762d000 00:00 0
f7e2f000-f7f8b000 r-xp 00000000 08:01
1073288                            /lib32/libc-2.9.so
f7f8b000-f7f8c000 ---p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8c000-f7f8e000 r--p 0015c000 08:01
1073288                            /lib32/libc-2.9.so
f7f8e000-f7f8f000 rw-p 0015e000 08:01
1073288                            /lib32/libc-2.9.so
f7f8f000-f7f92000 rw-p f7f8f000 00:00 0
f7f92000-f7fa7000 r-xp 00000000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa7000-f7fa8000 r--p 00014000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa8000-f7fa9000 rw-p 00015000 08:01
1073302                            /lib32/libpthread-2.9.so
f7fa9000-f7fab000 rw-p f7fa9000 00:00 0
f7fbc000-f7fc9000 r-xp 00000000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fc9000-f7fca000 r--p 0000c000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fca000-f7fcb000 rw-p 0000d000 08:01
5333910                            /usr/lib32/libgcc_s.so.1
f7fcb000-f7fce000 rw-p f7fcb000 00:00 0
f7fce000-f7fcf000 r-xp f7fce000 00:00
0                                  [vdso]
f7fcf000-f7fee000 r-xp 00000000 08:01
1073285                            /lib32/ld-2.9.so
f7fee000-f7fef000 r--p 0001e000 08:01
1073285                            /lib32/ld-2.9.so
f7fef000-f7ff0000 rw-p 0001f000 08:01
1073285                            /lib32/ld-2.9.so
ff8da000-ff8ef000 rw-p 7ffffffea000 00:00
0                              [stack]
Cancelado
I googled a lot, but can't find anything that guides me...
also I make some debugging in gdb:
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xf7d736c0 (LWP 20387)]
0xf7f14425 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7f14425 in __kernel_vsyscall ()
#1  0xf7da09a0 in raise () from /lib32/libc.so.6
#2  0xf7da2368 in abort () from /lib32/libc.so.6
#3  0xf7ddee4d in ?? () from /lib32/libc.so.6
#4  0xf7de5204 in ?? () from /lib32/libc.so.6
#5  0xf7de81e6 in ?? () from /lib32/libc.so.6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
#8  0x0804b7aa in enviar_caracter (fd=5, status=-3987288, c=49 '1') at
7sdio.c:145
#9  0x0804b820 in enviar_cadena (fd=5, status=-3987288, str=0x8a8c0c8
"132132132132") at 7sdio.c:163
#10 0x0804c387 in main (argc=2, argv=0xffc32934) at 7sd.c:221
(gdb) frame 7
#7  0x0804b3be in codificar_caracter (c=49 '1') at 7sdio.c:41
41      binario = malloc(sizeof(int)*8);  <----- call that causes error
(gdb) frame 6
#6  0xf7de95f5 in malloc () from /lib32/libc.so.6
so the program lines close to the error are this:
int  *binario;
printf("size=%d\n", sizeof(int)*8);
binario = malloc(sizeof(int)*8);
it seems like an error (bug) from malloc, but i cant believe that,
it's nearly impossible...
someone knows what's hapenning here??
thank you in advance

hello, in my experience(i had once the similar problem), i can just
guess,it might be problem of your usage of variable binario.
by exemple ,if u fill the binario more than sizeof(int)*8, and u
return the binario at the end of fonction. then u call the fonction
outside of this file,  u try to read the content of the allocated
memory region, it can cause this problem.
it's just a guess, try to track down where did u use the variable
binario.

Yes, I do something like that, it's in a function and I return
"binario"
Then I free binario outside. I've done this other times, worked good.
If it is this error, then it shouldn't work neither in 32 nor in 64
bits
 
J

JPerelli

You're (almost certainly) abusing some memory allocated with malloc -
buffer overwrite or something similar. This is corrupting the internal
structures used by malloc to manage its space.

Yes but it is easier to blame the other (malloc bug). Incredible what
I come to think when I have no clue.
The problem can't be detected until malloc (or one of the malloc/free
family) is next called, so that's when you get your error. This is not
where the corruption occured.

This page may help you - <http://www.gnu.org/s/libc/manual/html_node/
Heap-Consistency-Checking.html> - especially the MALLOC_CHECK_
discussion. Otherwise there are tools such as "Electric Fence" <http://
directory.fsf.org/project/ElectricFence/> which should help you.

Great, i'll check that. Tank you a lot!
 
K

Keith Thompson

David RF said:
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);

Your printf call with the "%lu" is still incorrect; it expects an
argument of type unsigned long, but you're giving it an argument of
type size_t, which may or may not be the same.

printf("size=%lu\n", (unsigned long)(sizeof(int)*8));
 
J

JPerelli

[...]
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);

Your printf call with the "%lu" is still incorrect; it expects an
argument of type unsigned long, but you're giving it an argument of
type size_t, which may or may not be the same.

printf("size=%lu\n", (unsigned long)(sizeof(int)*8));

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

That doesn't solve my problem.
 
J

JPerelli

You're (almost certainly) abusing some memory allocated with malloc -
buffer overwrite or something similar. This is corrupting the internal
structures used by malloc to manage its space.

The problem can't be detected until malloc (or one of the malloc/free
family) is next called, so that's when you get your error. This is not
where the corruption occured.

This page may help you - <http://www.gnu.org/s/libc/manual/html_node/
Heap-Consistency-Checking.html> - especially the MALLOC_CHECK_
discussion. Otherwise there are tools such as "Electric Fence" <http://
directory.fsf.org/project/ElectricFence/> which should help you.

Thank you, with that I fixed (bypassed) my issue.

From man malloc (glibc):

If MALLOC_CHECK_ is set to 0, any detected heap corruption is
silently
ignored; if set to 1, a diagnostic message is printed on stderr; if
set to 2, abort(3) is called immediately;
if set to 3, a diagnostic message is printed on stderr and the program
is aborted.

so I set MALLOC_CHECK_ to 0 and works (hides errors) great!
I will keep digging into the code, to see if I find some error...

Thank you, now i can at least run it, and I really nedded that.
 
P

Pere Pujal i Carabantes

Hola JPerelli!

El 2009-10-02
JPerelli va escriure en
comp.lang.c:
[...]
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);

Your printf call with the "%lu" is still incorrect; it expects an
argument of type unsigned long, but you're giving it an argument of
type size_t, which may or may not be the same.

printf("size=%lu\n", (unsigned long)(sizeof(int)*8));

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
That doesn't solve my problem.

Have you inspected _in detail_ the output of valgrind?

I´ve just been dealing whith a similar issue (running fine in valgrind,
crashing in "normal" runs).

The problem was far enouth from the point where the program crashed and
valgrind showed a "invalid write of size..." that I was not seeing because
it was merged whith all other output.

Hope this helps.

Pere
 
F

Flash Gordon

JPerelli said:
Thank you, with that I fixed (bypassed) my issue.

From man malloc (glibc):

If MALLOC_CHECK_ is set to 0, any detected heap corruption is
silently
ignored; if set to 1, a diagnostic message is printed on stderr; if
set to 2, abort(3) is called immediately;
if set to 3, a diagnostic message is printed on stderr and the program
is aborted.

so I set MALLOC_CHECK_ to 0 and works (hides errors) great!

Note that it is only hiding one symptom of the error. It is entirely
possible that there are other symptoms such as incorrect results that
you just have not noticed. Your code is still just as broken.
I will keep digging into the code, to see if I find some error...

You need to.
Thank you, now i can at least run it, and I really nedded that.

You may be able to run it, but you can't trust the output.
 
K

Keith Thompson

JPerelli said:
[...]
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);

Your printf call with the "%lu" is still incorrect; it expects an
argument of type unsigned long, but you're giving it an argument of
type size_t, which may or may not be the same.

printf("size=%lu\n", (unsigned long)(sizeof(int)*8));

That doesn't solve my problem.

I didn't expect it to.

More precisely, it solved one of your problems, but a fairly minor
one, not the one that you were asking about, and probably not one for
which you were seeing any symptoms.

Nevertheless, along with whatever else you're doing, you should write
your printf calls correctly.
 
J

JPerelli

Hola JPerelli!

El 2009-10-02
JPerelli va escriure en
comp.lang.c:


[...]
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);
Your printf call with the "%lu" is still incorrect; it expects an
argument of type unsigned long, but you're giving it an argument of
type size_t, which may or may not be the same.
printf("size=%lu\n", (unsigned long)(sizeof(int)*8));
--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
That doesn't solve my problem.

Have you inspected _in detail_ the output of valgrind?

I´ve just been dealing whith a similar issue (running fine in valgrind,
crashing in "normal" runs).

The problem was far enouth from the point where the program crashed and
valgrind showed a "invalid write of size..." that I was not seeing because
it was merged whith all other output.

Hope this helps.

Pere

Well, thank you so much!
It works great now!
It was just like you described.
I really appreciate the help that you all gave me.

Regards, Julian
 
J

JPerelli

     Your program now runs, but can you trust it to run correctly?
Should you believe its output?

     Here's the one thing you know for sure about your program: It
has a serious mistake somewhere.  Some part of the program stores
data in a place it doesn't "own," which means that (1) it might be
wiping out some data used by another part of the program, or (2)
some other part of the program may wipe out the incorrectly-stored
datum.  Either way, your program is likely to produce incorrect
results or to misbehave in odd ways.

     Here's an analogy: Your car's oil pressure gauge plummets to
zero, the temperature gauge spikes to HOT, and the CHECK ENGINE
light comes on; that's your program crashing.  Your response is
to put pieces of black tape over the gauges and lights so you no
longer see any signs of trouble.  Do you think this is a good
treatment for the engine?

    Set MALLOC_CHECK to 1 or 3, I'd say, and try to find and fix
what is going wrong.

     But, on the other hand, it's *your* program and you can do
with it what you will.  Set MALLOC_CHECK to 0, let the program
run, study its output, and invest all your money as the output
suggests, whether it's trustworthy or not ...

Yes, I was aware of that, but sometimes I need to drive the car and I
don't mind if it has or not the doors perfectly closed.
This piece of code was not so important and was crashing my whole
program, and I needed to work in other part now.
But now works excellent, valgrind doesn't complains at all. Thanks for
your help.
 
J

JPerelli

JPerelli said:
[...]
I see no errors in your code, use valgrind for more details and ...
use
printf("size=%lu\n", sizeof(int)*8);
or
printf("size=%zu\n", sizeof(int)*8); */ if C99 */
instead of
printf("size=%d\n", sizeof(int)*8);
Your printf call with the "%lu" is still incorrect; it expects an
argument of type unsigned long, but you're giving it an argument of
type size_t, which may or may not be the same.
printf("size=%lu\n", (unsigned long)(sizeof(int)*8));
That doesn't solve my problem.

I didn't expect it to.

More precisely, it solved one of your problems, but a fairly minor
one, not the one that you were asking about, and probably not one for
which you were seeing any symptoms.

Nevertheless, along with whatever else you're doing, you should write
your printf calls correctly.

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

ok, it was only for debug, i needed to print something there! :)
Thank you, I'll keep that on mind.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top