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

  • Home
  • SEARCH
  • 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 8770889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:39:01+00:00 2026-06-13T17:39:01+00:00

I am not sure why I am getting the below error. Strangely enough, this

  • 0

I am not sure why I am getting the below error. Strangely enough, this error doesn’t occur when I use Mac OS X, but it does when I use my Linux (Debian) partition.

-----------
Empty Queue: 0 0 0 0 0 0 0 0 0 0 

---------------
Populated Queue: 5 3 1 7 6 3 2 1 4 4 

-------------
After Dequeue: 3 1 7 6 3 2 1 4 4 0 
    Datum: 5

*** glibc detected *** ./queue_demo: free(): invalid next size (fast): 0x0000000000c73010 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x75b76)[0x7fde5c98db76]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x6c)[0x7fde5c9928ac]
./queue_demo[0x40098d]
./queue_demo[0x4008d8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7fde5c936ead]
./queue_demo[0x4006d9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:01 940937                             /home/dylan/Desktop/CST352_Gleason_Lab2/solution_1/queue_demo
00601000-00602000 rw-p 00001000 08:01 940937                             /home/dylan/Desktop/CST352_Gleason_Lab2/solution_1/queue_demo
00c73000-00c94000 rw-p 00000000 00:00 0                                  [heap]
7fde58000000-7fde58021000 rw-p 00000000 00:00 0 
7fde58021000-7fde5c000000 ---p 00000000 00:00 0 
7fde5c702000-7fde5c717000 r-xp 00000000 08:01 1079347                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fde5c717000-7fde5c917000 ---p 00015000 08:01 1079347                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fde5c917000-7fde5c918000 rw-p 00015000 08:01 1079347                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fde5c918000-7fde5ca95000 r-xp 00000000 08:01 1079316                    /lib/x86_64-linux-gnu/libc-2.13.so
7fde5ca95000-7fde5cc95000 ---p 0017d000 08:01 1079316                    /lib/x86_64-linux-gnu/libc-2.13.so
7fde5cc95000-7fde5cc99000 r--p 0017d000 08:01 1079316                    /lib/x86_64-linux-gnu/libc-2.13.so
7fde5cc99000-7fde5cc9a000 rw-p 00181000 08:01 1079316                    /lib/x86_64-linux-gnu/libc-2.13.so
7fde5cc9a000-7fde5cc9f000 rw-p 00000000 00:00 0 
7fde5cc9f000-7fde5ccbf000 r-xp 00000000 08:01 1079447                    /lib/x86_64-linux-gnu/ld-2.13.so
7fde5cea3000-7fde5cea6000 rw-p 00000000 00:00 0 
7fde5cebb000-7fde5cebe000 rw-p 00000000 00:00 0 
7fde5cebe000-7fde5cebf000 r--p 0001f000 08:01 1079447                    /lib/x86_64-linux-gnu/ld-2.13.so
7fde5cebf000-7fde5cec0000 rw-p 00020000 08:01 1079447                    /lib/x86_64-linux-gnu/ld-2.13.so
7fde5cec0000-7fde5cec1000 rw-p 00000000 00:00 0 
7fff13797000-7fff137b8000 rw-p 00000000 00:00 0                          [stack]
7fff137ff000-7fff13800000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted

This error happens when I call the destruct function in my Queue structure, in a test program written below.

#include <time.h>
#include <stdio.h>
#include "Queue.h"

int main(int argc, char* argv[])
{
   // create a "queue" data structure
   Queue_t* my_queue = construct(10);

   // generate a random seed
   srand( (unsigned)time(NULL) );

   // display the empty queue
   printf("-----------\n");
   printf("Empty Queue: ");
   display(my_queue);
   printf("\n");

   // populate the queue with random numbers
   int i = 0;

   for(; i < my_queue->maximum_count; ++i)
      enqueue(my_queue, rand() % 10);

   printf("---------------\n");
   printf("Populated Queue: ");
   display(my_queue);
   printf("\n");

   // dequeue, print the current queue and the datum
   int datum = dequeue(my_queue);

   printf("-------------\n");
   printf("After Dequeue: ");
   display(my_queue);
   printf("\tDatum: %d\n\n", datum);

   // clean up memory
   destruct(my_queue);

   return 0;
}

Here is my data structure:

#ifndef QUEUE_H
#define QUEUE_H

typedef struct Queue
{
   int  current_count;
   int  maximum_count;
   int  buffer[];       // queue uses an array
} Queue_t;


// routines to implement Queue-like functionality (FIFO)
// TODO: somehow encapsulate all these features in the struct itself.
//
Queue_t* construct(int buff_size);
void     destruct (Queue_t* queue);
void     display  (Queue_t* queue);
int      dequeue  (Queue_t* queue);
void     enqueue  (Queue_t* queue, const int datum);

#endif

Implementation:

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "Queue.h"

Queue_t* construct(int buff_size)
{
   Queue_t* queue = malloc(
      sizeof(Queue_t) + sizeof(int) * sizeof(Queue_t));

   assert(queue != NULL);
   queue->maximum_count = buff_size;
   queue->current_count = 0;
   memset(queue->buffer, 0, sizeof(int)*buff_size);

   return queue;
}

void destruct(Queue_t* queue)
{
   assert(queue != NULL);
   free(queue);  // error at this statement
   printf("Queue destroyed!\n");
}

void display(Queue_t* queue)
{
   int i = 0;

   for(; i < queue->maximum_count; ++i)
      printf("%d ", queue->buffer[i]);
   printf("\n");
}

void enqueue(Queue_t* queue, const int datum)
{
   assert(queue->current_count < queue->maximum_count);
   queue->buffer[queue->current_count] = datum;
   ++queue->current_count;
}


int dequeue(Queue_t* queue)
{
   int i = 1;
   int datum = queue->buffer[0];

   assert(queue->current_count > 0);

   for(; i < queue->maximum_count; ++i)
   {
      queue->buffer[i-1] = queue->buffer[i];
      queue->buffer[i] = 0;
   }

   --queue->current_count;

   return datum;
}
  • 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-13T17:39:02+00:00Added an answer on June 13, 2026 at 5:39 pm

    This looks like you have corrupted some data used by libc memory allocation functions. In your construct function shouldn’t we change

    Queue_t* queue = malloc(
          sizeof(Queue_t) + sizeof(int) * sizeof(Queue_t));
    

    to

    Queue_t* queue = malloc(
              sizeof(Queue_t) + sizeof(int) * buff_size);
    

    The following line in construct seems to cause the corruption now due to incorrect amount of memory being allocated for queue.

     memset(queue->buffer, 0, sizeof(int)*buff_size);
    

    When you apply the sizeof operator to a structure with a flexible array member, only fields other than the flexible array comprise the total structure size i.e. its size is 0. When you are allocating memory for such structures, you need to specify explicitly how many extra bytes you want at the end of the structure.

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

Sidebar

Related Questions

I'm getting below error...I'm not sure what this means as I have included helper
Hello not sure why Im getting this error. Basically I get it in these
Not sure why I'm getting this error and can't figure it out? The cycle
not sure what I'm missing here, but i keep getting the error. SQLSTATE[HY093]: Invalid
OK have just started getting this error and I'm not sure why. I have
i am not sure why i am getting this error i created a regular
This was working, but now i'm getting the below error when calling update_attributes :
I am getting the above error and I'm not sure how to fix it,
I keep getting this RuntimeError which I'm not sure how to fix. Here's what
I'm getting the error mentioned in the title and not sure what exactly I

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.