free touble
johny@softvation.com
johny@softvation.com
Thu Aug 9 06:54:00 GMT 2007
hi, all
i want to ask, why free function did not do properly as it expected
(happened in test_malloc.c), the usage memory (using malloc) still exist
please help me, i have another program it, doing malloc continously, and
free it when not needed, this happened several times,
after some looping, my memory become 0 free, and it got hang.i did some
investigation, and found there is something strange in free.
anyone got idea what happen and give me a solution?
thanks in advance
Johny Jugianto
using gcc:
$ gcc --version
gcc (GCC) 4.2.0
here is my machine info
$ uname -a
Linux localhost.svr 2.6.9-55.ELsmp #1 SMP Wed May 2 14:28:44 EDT 2007 i686
athlon i386 GNU/Linux
-RESULT: pmap for test_malloc.c after ready to insert-----------------
[nyto@nyto ~]$ pmap 5836
5836: ./test_malloc
007ad000 88K r-x-- /lib/ld-2.3.4.so
007c3000 4K r---- /lib/ld-2.3.4.so
007c4000 4K rw--- /lib/ld-2.3.4.so
007c7000 1176K r-x-- /lib/tls/libc-2.3.4.so
008ed000 8K r---- /lib/tls/libc-2.3.4.so
008ef000 8K rw--- /lib/tls/libc-2.3.4.so
008f1000 8K rw--- [ anon ]
08048000 4K r-x-- /home/nyto/test_malloc
08049000 4K rw--- /home/nyto/test_malloc
08dcb000 132K rw--- [ anon ]
b7ba2000 3920K rw--- [ anon ]
bfff0000 64K rw--- [ stack ]
ffffe000 4K ----- [ anon ]
total 5424K
-RESULT: pmap for test_malloc.c after done free-----------------------
[nyto@nyto ~]$ pmap 5836
5836: ./test_malloc
007ad000 88K r-x-- /lib/ld-2.3.4.so
007c3000 4K r---- /lib/ld-2.3.4.so
007c4000 4K rw--- /lib/ld-2.3.4.so
007c7000 1176K r-x-- /lib/tls/libc-2.3.4.so
008ed000 8K r---- /lib/tls/libc-2.3.4.so
008ef000 8K rw--- /lib/tls/libc-2.3.4.so
008f1000 8K rw--- [ anon ]
08048000 4K r-x-- /home/nyto/test_malloc
08049000 4K rw--- /home/nyto/test_malloc
08dcb000 15708K rw--- [ anon ]
b7ba2000 3920K rw--- [ anon ]
bfff0000 64K rw--- [ stack ]
ffffe000 4K ----- [ anon ]
total 21000K
-RESULT: pmap for test_malloc2.c after ready to insert----------------
[nyto@nyto ~]$ pmap 5841
5841: ./test_malloc2
007ad000 88K r-x-- /lib/ld-2.3.4.so
007c3000 4K r---- /lib/ld-2.3.4.so
007c4000 4K rw--- /lib/ld-2.3.4.so
007c7000 1176K r-x-- /lib/tls/libc-2.3.4.so
008ed000 8K r---- /lib/tls/libc-2.3.4.so
008ef000 8K rw--- /lib/tls/libc-2.3.4.so
008f1000 8K rw--- [ anon ]
08048000 4K r-x-- /home/nyto/test_malloc2
08049000 4K rw--- /home/nyto/test_malloc2
087c3000 132K rw--- [ anon ]
b7baa000 3920K rw--- [ anon ]
bfee6000 1128K rw--- [ stack ]
ffffe000 4K ----- [ anon ]
total 6488K
-RESULT: pmap for test_malloc2.c after done free----------------------
[nyto@nyto ~]$ pmap 5841
5841: ./test_malloc2
007ad000 88K r-x-- /lib/ld-2.3.4.so
007c3000 4K r---- /lib/ld-2.3.4.so
007c4000 4K rw--- /lib/ld-2.3.4.so
007c7000 1176K r-x-- /lib/tls/libc-2.3.4.so
008ed000 8K r---- /lib/tls/libc-2.3.4.so
008ef000 8K rw--- /lib/tls/libc-2.3.4.so
008f1000 8K rw--- [ anon ]
08048000 4K r-x-- /home/nyto/test_malloc2
08049000 4K rw--- /home/nyto/test_malloc2
087c3000 132K rw--- [ anon ]
b7baa000 3920K rw--- [ anon ]
bfee6000 1128K rw--- [ stack ]
ffffe000 4K ----- [ anon ]
total 6488K
-FILE: test_malloc.c--------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define JUMLAH 1000000
#define ISI 100
typedef struct _dodol
{
char *abc;
} dodol;
int main()
{
dodol **abc = (dodol**)calloc( JUMLAH, sizeof(dodol*) );
char *lala = (char*)malloc(sizeof(char)*ISI +1);
int i;
char a[10];
for(i=0; i<ISI; i++)
lala[i] = 'a';
lala[i]=0;
printf("ready to insert\n");
scanf("%s",a);
for(i=0; i<JUMLAH; i++) {
abc[i] = (dodol *)malloc(sizeof(dodol));
//free( abc[i] );
}
//printf("ready to free\n");
//scanf("%s",a);
for(i=0; i<JUMLAH; i++) {
free( abc[i] );
}
//free(abc);
printf("done free\n");
scanf("%s",a);
return 0;
}
-FILE: test_malloc2.c-------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define JUMLAH 1000000
#define ISI 100
typedef struct _dodol
{
char *abc;
} dodol;
int main()
{
dodol **abc = (dodol**)calloc( JUMLAH, sizeof(dodol*) );
char *lala = (char*)malloc(sizeof(char)*ISI +1);
int i;
char a[10];
for(i=0; i<ISI; i++)
lala[i] = 'a';
lala[i]=0;
printf("ready to insert\n");
scanf("%s",a);
for(i=0; i<JUMLAH; i++) {
abc[i] = (dodol *)malloc(sizeof(dodol));
free( abc[i] );
}
//printf("ready to free\n");
//scanf("%s",a);
for(i=0; i<JUMLAH; i++) {
//free( abc[i] );
}
//free(abc);
printf("done free\n");
scanf("%s",a);
return 0;
}
More information about the Gcc-bugs
mailing list