'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[0xb7e35356]
/lib/tls/i686/cmov/libc.so.6[0xb7e3655a]
/lib/tls/i686/cmov/libc.so.6(realloc+0x10b)[0xb7e3875b]
awk[0x80569d5]
awk[0x805430a]
awk[0x805453c]
awk[0x805465e]
awk[0x8054a11]
awk[0x804dec1]
awk[0x804ce0d]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7ddf450]
awk[0x8048fa1]
======= Memory map: ========
08048000-0805e000 r-xp 00000000 08:02 7468 /usr/bin/mawk
0805e000-08060000 rw-p 00015000 08:02 7468 /usr/bin/mawk
08060000-080e6000 rw-p 08060000 00:00 0 [heap]
b7c00000-b7c21000 rw-p b7c00000 00:00 0
b7c21000-b7d00000 ---p b7c21000 00:00 0
b7dbc000-b7dc6000 r-xp 00000000 08:02 10377 /lib/libgcc_s.so.1
b7dc6000-b7dc7000 rw-p 0000a000 08:02 10377 /lib/libgcc_s.so.1
b7dc7000-b7dc9000 rw-p b7dc7000 00:00 0
b7dc9000-b7f12000 r-xp 00000000 08:02 2372 /lib/tls/i686/cmov/libc-2.7.so
b7f12000-b7f13000 r--p 00149000 08:02 2372 /lib/tls/i686/cmov/libc-2.7.so
b7f13000-b7f15000 rw-p 0014a000 08:02 2372 /lib/tls/i686/cmov/libc-2.7.so
b7f15000-b7f18000 rw-p b7f15000 00:00 0
b7f18000-b7f3b000 r-xp 00000000 08:02 6015 /lib/tls/i686/cmov/libm-2.7.so
b7f3b000-b7f3d000 rw-p 00023000 08:02 6015 /lib/tls/i686/cmov/libm-2.7.so
b7f52000-b7f54000 rw-p b7f52000 00:00 0
b7f54000-b7f55000 r-xp b7f54000 00:00 0 [vdso]
b7f55000-b7f6f000 r-xp 00000000 08:02 70920 /lib/ld-2.7.so
b7f6f000-b7f71000 rw-p 00019000 08:02 70920 /lib/ld-2.7.so
bfc1e000-bfc33000 rw-p bffeb000 00:00 0 [stack]
./test_script: line 36: 15730 Aborted

I already search in google but can not find any clue. I've used same awk script file for various text file. some works fine, but some shows the above error.

Anyone know it? Thanks in advance.:smiley:

---------- Post updated at 07:12 AM ---------- Previous update was at 07:11 AM ----------

I think this error is due to access to array that I used in awk.

Your post is useless because there's no code to debug. None of us here have a crystal ball. Try putting some code up so people can look at it.

How did you expect us to be able to provide insight into what is wrong if there's nothing to look at?

I do have a crystal ball, but unfortunately it's in the shop right now.
Having a code sample would definitely help.
Also, it seems that you're using 'mawk'. What happens if use awk/nawk/gawk (if you have any of them)?

Sorry for late to put code

BEGIN {
        highest_packet_id = 0;      
}
{
	event = $1;
	time = $2;
	node = $3;
	trace_level = $4;
	packet_type = $7;
	packet_id = $6;

	# record AGT and cbr flow
        if ( trace_level == "AGT"&& packet_type == "cbr"  ) {
		if ( packet_id >=highest_packet_id ) 
			highest_packet_id = packet_id;    
		
		if (event=="s")
		{ 
			if ( start_time[packet_id] == 0 )  
               			start_time[packet_id] = time;
		}

		if (event=="r")
			end_time[packet_id] = time;
		else  
			end_time[packet_id] = -1; 			
         }
}
END {
      for  ( num = 0; num <= highest_packet_id; num++ ) {
        	start = start_time[num];
		end = end_time[num];
		 if ( start < end ) {
	     		delay = end - start;	
                }		             
      }
}

BTW, how can I upload my txt file here. it is about 7MB. thanks

---------- Post updated at 09:43 AM ---------- Previous update was at 09:37 AM ----------

sorted out!:rolleyes:

The txt file can be download from : MEGAUPLOAD - The leading online storage and file delivery service

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 11:04 AM ---------- Previous update was at 10:49 AM ----------

First of all, you're missing a '}' in the END block.
Secondly, in the END block you have a loop counting from 0 going through ALL the numbers to the highest REGARDLESS whether an ID was found or not. If the number/id has not been found, you still try to access the array indexed by this 'id'. My 'awk/nawk' on Solaris didn't complain - maybe your 'mawk' on whatever OS you're on is less 'forgiving'.
As an alternative try that:

END {
      #for  ( num = 0; num <= highest_packet_id; num++ ) {
      for  ( num in start_time) {
                start = start_time[num];
                end = end_time[num];
                 if ( start < end )
                        delay = end - start;
      }
}

OR (if you want to process the IDs in ascending order:

END {
      for  ( num = 0; num <= highest_packet_id; num++ ) {
                if (!(num in start_time)) continue
                start = start_time[num];
                end = end_time[num];
                 if ( start < end )
                        delay = end - start;
      }
}

You're not outputting anything in the END block, so it's hard to judge.

vgersh99, thanks for helping. Your suggestion is working perfectly. May be this is bug on mawk because gawk is work fine without error.