Computing.Net > Forums > Programming > Core dump on this code

Core dump on this code

Reply to Message Icon

Original Message
Name: janardhan
Date: September 2, 2003 at 16:15:38 Pacific
Subject: Core dump on this code
OS: Solaris 2.6
CPU/Ram: E250
Comment:

Wondering if anyone can point out my mistake: The code core dumps during the second iteration of the infinite loop. Here's the sample code:

struct input {
char *message;
};

...
for (;;) {
struct input *in = (struct input *) malloc
(sizeof(struct input)) ;
char *buffer = (char *)malloc(140 * sizeof
(char)) ;
ReadFromMsgQueue(to buffer) ;

in->message = (char *)malloc(140 * sizeof(
char);

free(buffer) ;
free(in->message) ;
free(in);
}

Works during the first iteration. However, during the second one, the code core dumps at in->message = (char *)...


Any tip is highly appreciated.


Report Offensive Message For Removal


Response Number 1
Name: Khash
Date: September 2, 2003 at 20:58:58 Pacific
Reply: (edit)

I copied and pasted this code and it works. I eliminated ReadFromMsgQueue(to buffer) ;
and added )to the end of
in->message = (char *)malloc(140 * sizeof(char));
and its working maybe the problem was the missing ).


Report Offensive Follow Up For Removal

Response Number 2
Name: janardhan
Date: September 2, 2003 at 22:25:51 Pacific
Reply: (edit)

Thanks for the reply.

After few hours of troubleshooting, I figured out that the problem was with synchronization of the structure variable from the main part of the program and within the thread.

The first mistake was passing the address of the structure and deleting it within the thread.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Core dump on this code

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge