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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:40:21+00:00 2026-05-23T19:40:21+00:00

I am running two separate threads in C, both doing some operations. Both threads

  • 0

I am running two separate threads in C, both doing some operations. Both threads include infinite loop. When I run this program couple of times, I always get a memory leak error.

*** glibc detected *** ./a.out: free(): invalid next size (normal): 0x08652510 ***

======= Backtrace: =========

/lib/libc.so.6(+0x6c501)[0x3d1501]

...

I believe it is a memory error, the problem is, when I always need to stop that program(cause im still testing it), i just terminate the program with Ctrl+C, so I believe I always miss the free(anything) command, which then causes the error.

Can you tell me how to avoid this situation? So I can free() memory even in case I terminate the program?

Next thing which comes to my mind is, when i wait a couple of minutes and then run the program again, it runs perfectly again

Thanks for any hints

void *lineOne(void *dataO)
{
  struct IPlist *IPlist = dataO;

  static struct ARP_entryI ARP_tableI[ARP_TABLE_SIZE];
  int neigh=0; //pocet susedov
  int neigh1=0; //stav pred tym
  int i;

  getAddress();

  while(1)
  {
    while (neigh == neigh1)
    {
      neigh =rcvBroad(IPlist, neigh); 
    }

    neigh1=neigh;

    for (i=neigh ; i<neigh+1; i++)
    {
      main_client(ARP_tableI, IPlist[i-1].IPaddr); // vysle tcp, prijme arp
      getAddress();
    }
  }

}

//pocuvaServer, odpoveda ARP
void *lineTwo()
{
  static struct ARP_entryO ARP_tableO[ARP_TABLE_SIZE];
  int line = from_local_arp(ARP_tableO); 

  main_server(ARP_tableO, line); // pocuva tcp, vysle arp

}


void main()
{
  static struct IPlist *IPlist[ARP_TABLE_SIZE];  

  pthread_t thread1, thread2;
  int  iret1, iret2;

  /* Create independent threads each of which will execute function */

  iret1 = pthread_create( &thread1, NULL, lineOne, (void *)IPlist); //(void *) &
  iret2 = pthread_create( &thread2, NULL, lineTwo, NULL); 

  pthread_join( thread1, NULL);
  pthread_join( thread2, NULL);


}
  • 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-23T19:40:25+00:00Added an answer on May 23, 2026 at 7:40 pm

    you could handle SIGINT, but it doesn’t matter, your code already corrupts the memory by the time you want to do that extra free() call.

    to find the problem compile it with -g and run it with valgrind.

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

Sidebar

Related Questions

I currently have my project running two separate threads (one for MFC operations, like
I have two machines, one running 2.4.18 and one running 2.4.20. Both run Java
I'm running a multi-threaded build with two dependant com.sun.tools.javac.Main.compile() invocations running on separate threads
I made this function to verify a user's twitter credentials. Its running on two
I got two projects running, both written in PHP. Now I want to merge
I have a tasks thread running in two separate instances of tomcat. The Task
I have inherited a middle tier system with some multi-Threading issues. Two different threads,
I'm wondering how I would go about running two separate queries within one mysqli_result.
I have two separate appliations running on the separate infrastructure. app-a is using MYSQL
I have two separate instances of Vim running. I would like to set up

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.