Hi All,
I am getting segmentation fault when I am allocating memory for the node second time.
struct host_msgs_list
{
[B]struct host_msgs_struct *message;[/B]
struct host_msgs_list *next;
};
struct host_msgs_list *root, *temp, *temp1;
root = NULL;
temp=root;
For the first message (i.e. OHAD), it’s able to allocate the memory.
We are able to process single message, but we are facing difficulty in processing multiple messages.
if (strncmp (&in_rec[OM_TRAN_CODE],OHAD, 4)==0)
{
rec_cnt = 1;
got_ohad = TRUE;
if(root == NULL)
{
/* Assign memory to Root */
root = (struct host_msgs_list*) malloc (sizeof(struct host_msgs_list));
/* Assign message */
memcpy(root->message,&in_rec,s_siz);
/* Next link */
root->next = NULL;
}
/* If Root is not NULL, the link list is not empty.
In this case, use Temp and traverse thro' the link list
and reach to the last element which is NULL. */
else
{
/* Traverse through the link list to find NULL element. */
while(temp->next != NULL)
{
temp = temp->next;
}
/* Assign memory to the last link. */
temp->next = (struct host_msgs_list*) malloc (sizeof(struct host_msgs_list));
/* Point to the location to which
you assigned the memory. */
temp = temp->next ;
/* Assign message
to the new memory location. */
memcpy(temp->message,&in_rec,s_siz);
/* Next link */
temp->next = NULL;
}
While allocating memory for the second node, the program is failing with segmentation fault error.
We indentified the spot where the error is occurring, which is colored red in the post.
Please have a look at it and reply to my email id as well.
Thanks,
Thirupathi reddy,
email snipped