Sponsored Content
Top Forums Programming ./match_pattern.out: malloc(): memory corruption: 0x0000000013a11600 *** Post 302553849 by JohnGraham on Friday 9th of September 2011 02:56:10 AM
Old 09-09-2011
Quote:
Originally Posted by shoaibjameel123
I reckon its the problem with malloc(), free() pair.
Memory corruption is normally due to you straying outside the bounds of an array - not with malloc()/free() statements matching up. You've probably overwritten some of the space next to a malloc()'d portion of memory that glibc expects to be able to use for keeping track of the memory region - go through with a debugger and have a look for bounds errors.

As an aside, here's the sort of thing you can expect if you did have a problem with malloc()/free() pairs:

Code:
[john@john-laptop tmp.u6Q7IbZntd]$ cat prog.c
#include <stdlib.h>

int main(void)
{
    void *p = malloc(1);
    free(p);
    free(p);
    return 0;
}
[john@john-laptop tmp.u6Q7IbZntd]$ gcc prog.c -o prog
[john@john-laptop tmp.u6Q7IbZntd]$ ./prog
*** glibc detected *** ./prog: double free or corruption (fasttop): 0x09ba3008 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6c501)[0x58b501]
/lib/libc.so.6(+0x6dd70)[0x58cd70]
/lib/libc.so.6(cfree+0x6d)[0x58fe5d]
./prog[0x8048425]
/lib/libc.so.6(__libc_start_main+0xe7)[0x535ce7]
./prog[0x8048361]
======= Memory map: ========
0051f000-00676000 r-xp 00000000 08:04 2793795    /lib/libc-2.12.1.so
00676000-00678000 r--p 00157000 08:04 2793795    /lib/libc-2.12.1.so
00678000-00679000 rw-p 00159000 08:04 2793795    /lib/libc-2.12.1.so
00679000-0067c000 rw-p 00000000 00:00 0 
0091c000-0091d000 r-xp 00000000 00:00 0          [vdso]
00ab9000-00ad3000 r-xp 00000000 08:04 2793551    /lib/libgcc_s.so.1
00ad3000-00ad4000 r--p 00019000 08:04 2793551    /lib/libgcc_s.so.1
00ad4000-00ad5000 rw-p 0001a000 08:04 2793551    /lib/libgcc_s.so.1
00dd4000-00df0000 r-xp 00000000 08:04 2793792    /lib/ld-2.12.1.so
00df0000-00df1000 r--p 0001b000 08:04 2793792    /lib/ld-2.12.1.so
00df1000-00df2000 rw-p 0001c000 08:04 2793792    /lib/ld-2.12.1.so
08048000-08049000 r-xp 00000000 08:04 1220779    /tmp/tmp.u6Q7IbZntd/prog
08049000-0804a000 r--p 00000000 08:04 1220779    /tmp/tmp.u6Q7IbZntd/prog
0804a000-0804b000 rw-p 00001000 08:04 1220779    /tmp/tmp.u6Q7IbZntd/prog
09ba3000-09bc4000 rw-p 00000000 00:00 0          [heap]
b7500000-b7521000 rw-p 00000000 00:00 0 
b7521000-b7600000 ---p 00000000 00:00 0 
b76fc000-b76fd000 rw-p 00000000 00:00 0 
b7714000-b7716000 rw-p 00000000 00:00 0 
bffdf000-c0000000 rw-p 00000000 00:00 0          [stack]
Aborted

 

10 More Discussions You Might Find Interesting

1. Programming

malloc gives the same memory to two different nodes. How to deal with it?

When allocating memory for two different nodes, the resulting memory are the same. Clearly, this will lead to a mistake. This happened in a function. And the process must be in a function. (gdb) p tree->list $43 = (node *) 0x8be4180 (gdb) p tree->list $44 = (node *) 0x8be4180 At the... (2 Replies)
Discussion started by: cdbug
2 Replies

2. UNIX for Dummies Questions & Answers

'memory corruption' error when using Awk

Hello, everyone. I got the following error when I am using awk to analysis some text file: *** glibc detected *** awk: malloc(): memory corruption: 0x080c67f8 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6 /lib/tls/i686/cmov/libc.so.6... (5 Replies)
Discussion started by: kooyee
5 Replies

3. Programming

Why memory allocated through malloc should be freed ?

Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory. Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies

4. Programming

Why does this occur? *** glibc detected *** malloc(): memory corruption: 0x10013ff8 ***

there seems not to be error in this segment. In some computers, it can work well. But in others, it will give a failure. why it ocurrs and how to deal with it? in a function: if( *ver == NULL ) { *ver = (vertex *) malloc(sizeof(vertex)); //this line ... (17 Replies)
Discussion started by: cdbug
17 Replies

5. Programming

readdir and dynamic array memory corruption

Hi everyone I am developing an utility. At some part of it I read directory entries to a dynamic array: struct list It stores pointers to items: list.entries, which are structures: struct entry If a number of files in a directory is greater then number of elements an array was initially... (11 Replies)
Discussion started by: torbium
11 Replies

6. Programming

*** glibc detected *** ./a.out: malloc(): memory corruption (fast):

*** glibc detected *** ./a.out: malloc(): memory corruption (fast): Posted A minute ago M trying to make multiway tree and dont know what happend when this part of code get executed: 01void ins(NODE *ptr) 02{ 03 //working 04 if(ptr!=NULL) 05 { 06 SNODE *var=NULL; 07 var=(SNODE... (3 Replies)
Discussion started by: exgenome
3 Replies

7. Programming

*** glibc detected *** : malloc(): memory corruption (fast)

Hi Friends, while executing the below code, am getting *** glibc detected *** ./ok: malloc(): memory corruption (fast) error, please suggest how to solve this issue. #include <stdio.h> #include <string.h> #include <sqlca.h> #include <alloca.h> /* Define constants for VARCHAR... (2 Replies)
Discussion started by: mpjobsrch
2 Replies

8. Programming

*** glibc detected *** ./a.out malloc() memory corruption

I am facing a problem of memory corruption. The loop runs for the first time but does not go through the second time. What could be the problem? for(int z=0;z<2;z++) { fp=fopen("poly.dat","r"); /*do something which reads this file into a 2D array*/ fclose(fp); ... (10 Replies)
Discussion started by: dare
10 Replies

9. Solaris

Solaris 10 Shared Memory Corruption with X11

I am having a problem with shared memory corruption. I have two 86 servers running Solaris 10 (150400-06). One of the servers is accessed by a Sun Ray thin client Version 11.1.3.0.2.6. I login into server one from the thin client. I then ssh -X to server two. When a process that contains a... (2 Replies)
Discussion started by: salerno
2 Replies

10. Programming

Memory corruption in dynamic array of strings

I put together a C function to add strings to a dynamic array of strings (mostly for educational purpose to explain pointers to my kid). It works, but sometimes one or two strings in the array becomes corrupted. Running example on 64 bit Ubuntu, gcc ver. 4.8.4 Hope my code is self-explanatory: ... (2 Replies)
Discussion started by: migurus
2 Replies
dos2unix(1)						      General Commands Manual						       dos2unix(1)

NAME
dos2unix - DOS/MAC to UNIX text file format converter SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates dos2unix under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. dos2unix Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au> Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org> MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
unix2dos(1) mac2unix(1) 1995.03.31 dos2unix v3.0 dos2unix(1)
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy