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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:09:40+00:00 2026-06-12T09:09:40+00:00

EDIT: Changed Title to ignore my assumption. I have a library, written in c,

  • 0

EDIT: Changed Title to ignore my assumption.

I have a library, written in c, which uses posix message queue to pass pointers to some runtime data between threads.

In cases where the data is coming from user application, everything seems to work fine, and I am able to access the data pointed by the pointer to a structure, coming from the message queue.

Now, I have a special case where the library itself will do a malloc of one instance of the structure, set a flag and send it to the same queue. On the receiving end, the structure is empty and the flag is zero. Calling free on the pointer causes a crash.

Here’s code:

volatile s_thestruct * volatile data = malloc(sizeof(s_thestruct));
data->flags = THE_FLAG;
mq_send(handle, (char *)&data, sizeof(s_thestruct *), 1)

And on the receiving end:

ssize_t read = mq_receive(handle, (char*)&data, sizeof(s_thestruct*), NULL);
if(read != sizeof(s_thestruct *))
{
 // Error handling, no problems here
}
if(data->flags == THE_FLAG)
{
// Do something, never gets here
}
// Do something else, no it is not freed here

// Finally
free(data); // <--CRASH

And I will get:

*** glibc detected *** /usr/bin/applicationthingy: free(): invalid pointer: 0x08053cf0 ***

Followed by dump.
Within the memory map dump I find:

....
08048000-0804a000 r-xp 00000000 08:01 802680     /usr/bin/applicationthingy
0804a000-0804b000 r--p 00001000 08:01 802680     /usr/bin/applicationthingy
0804b000-0804c000 rw-p 00002000 08:01 802680     /usr/bin/applicationthingy
0804c000-0806f000 rw-p 00000000 00:00 0          [heap]
b6e00000-b6e21000 rw-p 00000000 00:00 0 
....

So, anyone got any suggestions of what’s going on here?

  • 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-12T09:09:40+00:00Added an answer on June 12, 2026 at 9:09 am

    That (passing pointers) should work okay, assuming they’re from the same address space.

    The only thing I can think of is if there’s a chance the queue could be being written from a separate process? That would make pointers useless since what they’re pointing to is totally different in different processes.

    To be honest though, I wouldn’t pass pointers around like that unless the structure itself was massive. If you pass the structure, you gain all the advantages of being able to do proper inter-process queues.

    The other thing to check is is the library is somehow getting its allocations from a different memory arena than your main code. That would be a circumstance that would cause the free failure but probably not the incorrect flags since, even if they’re using different arenas, they would both be in the same address space.

    At a bare minimum, you should be printing out the value of data on the sending and receiving side, to ensure that it’s coming through unscathed. It’s entirely possible some other piece of code could be corrupting it (a la buffer overflows and so forth).

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

Sidebar

Related Questions

EDIT: I have changed the question as it was too localized and gained negative
Edit: Changed question title from Does C# allow method overloading, PHP style (__call)? -
Edit: My original title has been sort of changed. I suspect the current title
EDIT : Changed title from inheritance to composition. Left body of question unchanged. I'm
(edit note: I changed the Title to R: enumerate column combinations of a matrix,
Edit: Title changed, as @Gunner pointed out that this is not a buffer overflow.
EDIT:I've changed the title, because the issue had nothing to do with IE image.load()
EDIT: Changed title to actually be correct I'm trying to simulate a modal popup
EDIT: changed the title. I didn't know it at the time but this is
Edit: Changed the title. I'm less interested in the two segments being the same,

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.