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 8781073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:12:26+00:00 2026-06-13T20:12:26+00:00

When I am freeing my memory in this part of code…i am getting an

  • 0

When I am freeing my memory in this part of code…i am getting an error showing as :free(): invalid next size (fast)

int insertRecord(char *record,int recordSize,long dataPageNumber)
{
datapage *dataPage=(datapage *)malloc(sizeof(datapage));
readPage(dataPage,dataPageNumber);

slotentry slot;

//for checking and freeslotnumber storage
int freeSlotNumber=-1;
int negativeFlag=0;
int freeFlag=0;

if(recordSize+sizeof(slotentry)<=dataPage->cfs)
{
    slot.slotsize = recordSize;
    slot.slotaddress = dataPage->cfsptr;
    dataPage->cfs -= (recordSize+sizeof(slotentry));
    dataPage->cfsptr += recordSize;
    dataPage->slotcount++;

    memcpy(&dataPage->data[slot.slotaddress],record,recordSize);

    free(dataPage);
    return 1;
}

After executing free(dataPage) i am getting the above error…

typedef struct
{
   int pagenumber;
   int priority;
   long dirPageNo;
   long cfs;
   int cfsptr;
   int slotcount;
   char data[1];
} datapage;

typedef struct
{
   int slotaddress;
   int slotsize;
} slotentry;

I had kept the free(dataPage) before the memcpy it’s working fine but after memcpy it’s not working.. and showing the error….Can any one help me from this issue…

  • 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-06-13T20:12:28+00:00Added an answer on June 13, 2026 at 8:12 pm

    You are probably getting this due to writing outside the boundaries if the dataPage->data entry. This struct entry is just a single byte long, so unless slot.slotaddress==0 and recordSize==1, you will be writing to whatever memory lies after the end of the datapage struct. This memory corruption is probably what is causing your free error.

    To track down this type of error, I recommend running your program through valgrind:

    valgrind progname args
    

    This in this case, you will probably get messages about “invalid writes”, which tell you that you are writing outside the boundaries of your arrays.

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

Sidebar

Related Questions

My code is using many Dictionaries and I'm having issues freeing memory from all
Sometimes in execution I get this error message in VS2010 when trying to free
Been looking at this code for too long and I am getting gloomy any
I have a structure which contains some elements, i free the memory of this
In C, which is the better practice when it comes to freeing memory returned
In java, it automatically freeing up memory resouces by GC.But we have not only
Is deleting a pointer same as freeing a pointer (that allocates the memory)?
I've been thinking if there's a way how to speed up freeing memory in
I am pretty proficient with C, and freeing memory in C is a must.
This is a function call (so it is just a part of the whole

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.