Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6843111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:12:24+00:00 2026-05-27T00:12:24+00:00

When I try to delete the structure that I got from Queue.It will throw

  • 0

When I try to delete the structure that I got from Queue.It will throw runtime heap error.

here is my sample.

   /* "Message_content" structure hold the content of message and body. */
   typedef struct msgContent
   {
     char *message;
     char *body;
     struct msgContent *nextptr;
   }Message_content;

static Message_content *frontptr;
static Message_content *rearptr;

Message_content* msgContent;
msgContent = QueueDelete();
free(msgContent); //**error happens while calling this function**.

Here is my QueueDelete() function in c.

static Message_content* QueueDelete()
{
Message_content *tempMsgContent = NULL;

if(frontptr == NULL)
{
}
else if(frontptr==rearptr)
{
    tempMsgContent = frontptr;
    tempMsgContent->nextptr = NULL;
    frontptr = rearptr = NULL;
}
else
{
    tempMsgContent = frontptr;

    frontptr = frontptr->nextptr;
            tempMsgContent->nextptr = NULL; // rectify the problem said by philong
}
return tempMsgContent;
}

EDIT
Add Queue Insert Function which will give meaning to my code.

here is my Queue Insert function in c

  static int QueueInsert(char *message ,char *body)
  {
    Message_content *tempMsgContent  = (Message_content*) malloc(sizeof(Message_content*));
   if(rearptr == NULL && frontptr == NULL) 
   {
    rearptr = tempMsgContent;
    rearptr->message = message;
    rearptr->body = body;
    rearptr->nextptr=NULL;
    frontptr = rearptr;
    return 1;
   }
    rearptr->nextptr = tempMsgContent;
    rearptr = rearptr->nextptr;
    rearptr->body = body;
    rearptr->message = message;
    rearptr->nextptr = NULL;
    return 1;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:12:24+00:00Added an answer on May 27, 2026 at 12:12 am

    This might be your problem:

    tempMsgContent = frontptr;
    tempMsgContent->nextptr = NULL;
    frontptr = frontptr->nextptr;
    

    You set the nextptr of tempMsgContent to NULL, which is good, but frontptr and tempMsgContent still point to the same memory location!

    Set the nextptr to NULL after changing the frontptr.

    Edit Checking through your QueueInsert code, I see this line:

    Message_content *tempMsgContent  = (Message_content*) malloc(sizeof(Message_content*));
    

    What that does is allocate memory enough for a pointer (sizeof(Message_Content*))! You should use sizeof(Message_Content) without the asterisk. This will certainly mess upp your heap!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Through CommandName=Delete I try to delete a line from the ListView control but not
So I have a boosted queue class that helps multi-threading described here . In
We've got a database that generally has this structure: Master Record Table id (pk)
I have some code that throws causes syncdb to throw an error (because it
I'm looking to try to make an efficient delete method to work on a
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
The end goal is to have some form of a data structure that stores
I'm designing a new system and finding that I am struggling with the structure
I'm trying to write a PowerShell script that will do the following: Executes a
I'm trying to delete the highest value from a group. Given this data: group_table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.