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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:36:45+00:00 2026-06-16T06:36:45+00:00

Alternatively: duplicate of Facing an error — glibc detected free invalid next size (fast)

  • 0

Alternatively: duplicate of Facing an error — glibc detected free invalid next size (fast).

When I compile and run this code, I get an error message:
“realloc(): invalid next size: 0x0000000002483010”

I’ve been trying to find a solution for this for the last 6 hours without any luck..

Here are the relevant parts of my code-

#include<stdio.h>
#include<stdlib.h>

typedef struct vertex
{
    char* name;
    int id;
    int outDegree;
}vertex;

int main(){
    vertex *tmpVertice;
    vertex *vertices = (vertex*)calloc(1, sizeof(vertex));
    int p=1;
    while(p<20){
        vertex temp={"hi",p,0};
        vertices[p-1]=temp;
        tmpVertice=(vertex*)realloc(vertices,p);
        if(tmpVertice!=NULL) vertices=tmpVertice;
        p++;
    }
    return 0;
}
  • 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-16T06:36:46+00:00Added an answer on June 16, 2026 at 6:36 am

    realloc frees any previous buffer if necessary so the lines free(vertices) and free(tmpVertice) in your loop are wrong and should be removed.

    Edit: I’ve included an updated version of your program below with further fixes. You needed to realloc p*sizeof(vertex) rather than p bytes. You were writing beyond the end of the array then growing it. I’ve changed to realloc at the start of the loop

    int main(){
        vertex *tmpVertice;
        vertex *vertices = NULL;
        int p=1;
        while(p<20){
            vertex temp={"hi",p,0};
            tmpVertice=realloc(vertices,p*sizeof(vertex));
            if(tmpVertice==NULL) {
                printf("ERROR: realloc failed\n");
                return -1;
            }
            vertices=tmpVertice;
            vertices[p-1]=temp;
    
            p++;
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C++ Error: free(): invalid next size (fast): That's a C++ question (albeit
Possible Duplicate: C# - Is there a better alternative than this to ‘switch on
Possible Duplicate: Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘springSecurityFilterChain’ is defined In my Spring
Ok this is not duplicate of Alternative to Process.Start() because my question is something
I may have either misunderstood how to use the ON DUPLICATE KEY syntax, alternatively
Possible Duplicate: Super fast getimagesize in php I want to get the image sizes
... or alternatively an Array which prevents duplicate entries. Is there some kind of
Before I get flagged for duplicate, I have the code from Dynamic json object
I really hope this isn't a duplicate. I tried to search for my question
Possible Duplicate: C# - Is there a better alternative than this to ‘switch on

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.