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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:38:41+00:00 2026-06-10T10:38:41+00:00

So I’m having a strange problem that I’m hoping someone can shed some light

  • 0

So I’m having a strange problem that I’m hoping someone can shed some light on… I have the following code:

#include <unistd.h>
#include <mcheck.h>
#include <pthread.h>

static void *run(void *args)
{
  sleep(1);
  return NULL;
}

int main()
{
  mtrace();
  pthread_t thread;
  pthread_create(&thread, NULL, run, NULL);
  pthread_join(thread, NULL);

  return 0;
}

And I compile I’ve compiled it in these 2 ways:

g++ -static program.cpp -lpthread

and

g++ program.cpp -ltpthread

When I look at the mtrace’s output (mem.out in my case)

I see the following when i use the -static option, mtrace reports:

Memory Not freed:
__________________
   Address      Size   Caller
   0x085ac350   0x88   program.cpp:0

But when I exclude the -static option, mtrace reports the glorious:

No memory leaks.

So any ideas as to whats 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-10T10:38:42+00:00Added an answer on June 10, 2026 at 10:38 am

    Here’s a recipe for reproducing this on my regular desktop Linux system (FC-17):

    #include <mcheck.h>
    #include <pthread.h>
    
    extern "C" { static void *run(void *) { return 0; } }
    
    int main() {
      mtrace();
      pthread_t thread;
      pthread_create(&thread, 0, run, 0);
      pthread_join(thread, 0);
      return 0;
    }
    

    Compiled with g++ -g -static -pthread. This is how I executed it to get the mtrace error:

    $ MALLOC_TRACE=mt.txt mtrace ./a.out mt.txt
    
    Memory not freed:
    -----------------
               Address     Size     Caller
    0x00000000011a9c90    0x110  at 0x43d7f9
    

    I have a 64 bit system, so the size doesn’t match. When I disassemble the address in gdb, it gives this:

    (gdb) disass 0x43d7f9
    Dump of assembler code for function _dl_allocate_tls:
       0x000000000043d7c0 <+0>:     mov    %rbx,-0x20(%rsp)
       0x000000000043d7c5 <+5>:     mov    %rbp,-0x18(%rsp)
    ...
       0x000000000043d7f4 <+52>:    callq  0x428150 <calloc>
       0x000000000043d7f9 <+57>:    test   %rax,%rax
       0x000000000043d7fc <+60>:    je     0x43d8e0 <_dl_allocate_tls+288>
    ...
    

    So it looks like some thread local storage was allocated for the thread. It seems like a one time allocation per thread, because there are no additional allocations when I added a pthread_create call after the join, while there was one when I added it before the join. The _dl_allocate_tls suggests this is normally a functioned called during dynamic linking, but it seems it is being called during thread stack initialization. A grep through the glibc code shows it is being called in allocate_stack.c.

    There does seem to be corresponding calls to _dl_deallocate_tls in glibc, so I think this error is harmless. valgrind does not pick up any memory leaks.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a small JavaScript validation script that validates inputs based on Regex. 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.