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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:31:20+00:00 2026-06-12T12:31:20+00:00

my program is failing with stack smashing detected and the only messages than I

  • 0

my program is failing with stack smashing detected and the only messages than I have from Valgring is “blocks are possibly lost in loss record” repetead three times, and
I don’t know how to solved.

==3726== 144 bytes in 1 blocks are possibly lost in loss record 74 of 87
==3726==    at 0x4025315: calloc (vg_replace_malloc.c:467)
==3726==    by 0x4010CD7: allocate_dtv (dl-tls.c:300)
==3726==    by 0x401146B: _dl_allocate_tls (dl-tls.c:464)
==3726==    by 0x40405C6: pthread_create@@GLIBC_2.1 (allocatestack.c:570)
==3726==    by 0x806BF36: Thread::Thread(void* (*)(void*), void*) (os.cpp:203)

this is the code and Valgrind is pthread_create call.

Thread::Thread( PFUNC func, void * arg )
{
    int s = pthread_create( &_ThreadId, NULL, func, arg);  //here is msg from valgrind

    if (s != 0)
            throw EXCEPT_NOTHREAD;

    pthread_detach( _ThreadId ); 

}

Please can you help me what is wrong with the Thread function? I read in other similar questions that pthread_detach has to be before to create a thread?
thanks a lot in advance.

  • 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-12T12:31:21+00:00Added an answer on June 12, 2026 at 12:31 pm

    Please can you help me what is wrong with the Thread function?

    There’s nothing “wrong” as such; it’s just not releasing the thread’s resources before the end of the program, and Valgrind is reporting this as a memory leak. Since you’ve detached the thread, its resources won’t be released until the thread terminates. If it doesn’t terminate before the program does, then they might be reported as leaked.

    I read in other similar questions that pthread_detach has to be before to create a thread?

    You don’t need to use pthread_detach; that’s used to make the thread responsible for freeing its own resources. If you don’t use it, then another thread will need to call pthread_join when it’s time to stop the thread.

    If you want to clean up the leak, then instead of detaching the thread, you’ll have to keep hold of the thread handle (which I guess you’re already doing, assuming _ThreadId is a member variable). Then, before the program ends, tell the thread to stop and then call pthread_join to wait for it and release all of its resources. Whether it’s worth the hassle of doing that to remove a (probably harmless) warning is up to you, but a clean shutdown might help to avoid more serious potential problems.

    By the way, you shouldn’t use names like _ThreadId which start with a _ followed by an upper-case letter; names like that are reserved.

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

Sidebar

Related Questions

I have a program failing with: terminate called after throwing an instance of 'std::bad_alloc'
I have a VB6 program that is failing on a particular machine. The nature
We have a legacy 3rd party program that is failing with the error Class
I can't figure out why this program is failing. #!/usr/bin/env python from __future__ import
I have a failing C program, and i've narrowed it down to a fork()
Imagine we have a program trying to write to a particular file, but failing.
program to output all 4 digit numbers where no prior digit is greater than
We have a .NET application which targets .NET 3.5. Our clients run it from
The program runs fine for a few minutes and then ReadFile starts failing with
I have a program I'm testing that has its close button enabled at one

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.