Memory fault(Coredump)


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Memory fault(Coredump)
# 1  
Old 07-05-2012
Memory fault(Coredump)

Hi,

In my application we have one job which is used to process the files. But that job is failing with memory fault while processing a file or while shutting down the job. Sometime it generates the coredump and sometimes not. When I analysed the core dump I got below code snippet where it failed,

Code:
if ( addlUsage.pParamVal != NULL )
      {
                free (addlUsage.pParamVal);
                addlUsage.pParamVal = NULL;
      }

It failed while trying to free memory 'free (addlUsage.pParamVal);'.

When I analyzed the addlUsage.pParamVal value then I got one junk character at the end. So I added the \0 at the end after allocating the memory for it (o_pADUbuffer in below code is addlUsage) and then copied required value to addlUsage.pParamVal . Please see below,

Code:
lenOfVarADU = sizeOfAddlUsage - sizeOfFixedAddlUsage;
o_pADUbuffer->pParamVal = (char *)malloc((sizeOfAddlUsage - sizeOfFixedAddlUsage) + 1);
o_pADUbuffer->pParamVal[lenOfVarADU] = '\0';
 
memcpy(o_pADUbuffer->pParamVal, temp_buf + inputBuffPosIndx,
                   (sizeOfAddlUsage - sizeOfFixedAddlUsage));

But still I am getting same issue.

Please help....Thanks in advance.

Last edited by Scrutinizer; 07-05-2012 at 04:37 AM.. Reason: code tags
# 2  
Old 07-05-2012
No.

Your code has done pointer arithmetic on the pointer object you are trying to free.
malloc() keeps data about the pointer adjacent to the actual place in memory the pointer references at the start, so free() thinks it has to work on memory the process does nto own. Boom.

Use Electric Fence or valgrind to find where. These are available for a lot of platforms.

Failing that look at driver's code here:
memory stack problem
# 3  
Old 07-06-2012
Actually this problem is coming in production environment and is not reproducible in the test environment. I cannot debug the code in production environment. And as it is not reproduced in test environment, there is no use to debug the code there. In this case what can be done?

---------- Post updated 07-06-12 at 12:21 AM ---------- Previous update was 07-05-12 at 11:26 PM ----------

One more thing, we upgraded our system fex months ago and then only this issue is coming. Before everything was fine. I checked the code before and after upgradation and there are minor changes. also this issue is coming on HP-UX machine and not on Solaris machine.
# 4  
Old 07-06-2012
Yes, abusing memory like this means your code will be subject to inexplicable crashes in some places but not others, debug compiles but not release ones, and such and like because whether the memory you're accidentally trashing is
a) valid
b) occupied by anything that will cause the program to crash later

...is system-dependent, compiler-dependent, and environment-dependent.

That doesn't mean they don't all have the bug. They're all trashing memory they're not supposed to.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Memory fault(coredump)

I am writing a program that copies a program and prints the program with a line count. this is the program I wrote: #include <stdio.h> main() { int c; int nl_cnt = 0; while((c = getchar()) != EOF){ if(c = '\n'){ nl_cnt++;... (3 Replies)
Discussion started by: heywoodfloyd
3 Replies

2. AIX

Error: Memory fault(coredump)

Hi Experts, While running a command, i saw this error below # ls -lrt total 74008 -rw-r--r-- 1 rr57104 edcfes 37889134 May 16 12:41 LGTOnw.clnt.7.4.2.0.bff.tar.gz drwxr-xr-x 2 root system 256 May 18 12:42 lost+found # gunzip LGTOnw.clnt.7.4.2.0.bff.tar.gz Memory fault(coredump) ... (2 Replies)
Discussion started by: EngnrRG
2 Replies

3. Shell Programming and Scripting

Memory fault(coredump) while using cat cmd

i have few log files that are input to my perl script... i am executing the script as below cat RTR*.log | test.pl and getting the following error -ksh: 25014: Memory fault(coredump) cat: write error: Connection reset by peer can anyone help me on this.... Thanks in... (2 Replies)
Discussion started by: niteesh_!7
2 Replies

4. Programming

Memory fault(coredump) while using Environment variables

Hi, Actually I am facing one issue while using the getenv() in the C/C++ program. I want to take the file path from environment variables and if am not defining the environment path, its showing the message like this…! Memory fault(coredump) Actually I want to handle the error ,... (6 Replies)
Discussion started by: Kattoor
6 Replies

5. Shell Programming and Scripting

Segmentation Fault(coredump)

I'm getting this error when trying to run a Acucobol program thru UNIX.. Segmentation Fault(coredump) Precompiler error prevents compilation of xxxxxx.co. Please help me in this case.. (1 Reply)
Discussion started by: Manish4
1 Replies

6. Solaris

memory fault (coredump)

Getting memory fault (coredump) and segmentation fault(coredump) when i tried javac or java -version. what could be the problem? Regards Eswar (2 Replies)
Discussion started by: BhuvanEswar
2 Replies

7. Ubuntu

Memory fault(coredump)

Hey guys, I am new to the Linux world and have a question to post. When I ssh from a HP-UX machine to a ubuntu machine I get the following error message Memory fault(coredump) i.e. ssh 192.168.1.3 I get this message as shown below Memory fault(coredump) Can someone please explain... (2 Replies)
Discussion started by: fkaba81
2 Replies

8. AIX

Segmentation fault(coredump)

Hi All Can anybody help me? When ever am trying to run topas system gives me an error Segmentation fault(coredump) does anybody ahve solution for this? (4 Replies)
Discussion started by: vjm
4 Replies

9. Programming

Memory fault(coredump)

Dear All, I made a program which do some simple jobs like reading data from other process's shared memory and writing messages to the queues of other process. what happens is my program works fine and do all the task as expected but then then program ends it give Memory fault(coredump). I... (0 Replies)
Discussion started by: ralo
0 Replies

10. UNIX for Dummies Questions & Answers

Coredump (memory fault)

We are running a SQR program on Unix Platform with Oracle RDBMS. It's an interfacing program to integrate data from foreign sites to PeopleSoft database, using a flat file input. After many hours of processing, the program stops with a coredump error (memory fault). With top command we noticed... (1 Reply)
Discussion started by: araziki
1 Replies
Login or Register to Ask a Question

Featured Tech Videos