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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:18:11+00:00 2026-06-12T23:18:11+00:00

I have segmentation fault in my code. I’m curious if I allocate some space

  • 0

I have “segmentation fault” in my code. I’m curious if I allocate some space using “malloc()” in a function. After the function finished, is the space still valid?
Further question, when a create a child thread like this, I suppose it exists even after its parent exits. I’m using GCC in Linux.

void foo(){
    void *child_stack;
    child_stack=(void*)malloc(16384);
    child_stack += 16384;
    clone((void*)do_function,child_stack,0,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-06-12T23:18:12+00:00Added an answer on June 12, 2026 at 11:18 pm
    1. Memory created with malloc goes on the heap, which is available until it is explicitly destroyed with free. That’s the main reason to use malloc instead of creating variables on the stack, which are destroyed when they fall out of scope (eg, a function returning) and the stack frame is destroyed. The segfault is probably because you’re allocating 16384 bytes, then moving the pointer forward 16384 with the += (why are you doing this?) before passing it to a function that presumably tries to access it.

    2. I’m not 100% sure, but From the wait() man page,

      If a parent process terminates, then its "zombie" children (if any) are adopted by init(8), which automatically performs a wait to remove the zombies.
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a segmentation fault in the code below, but after I changed it
i have some question. I try this code and recieve Segmentation fault error: #include
When I run this code, I have error Segmentation fault (core dumped). But without
I faced a problem using a Boost variant. I have a segmentation fault when
I have wrapped my C/C++ code using SWIG in Perl. I have few segmentation
In some of our code; we are getting a segmentation fault and the gdb
I have written a segmentation fault handler, using sigsetjmp and siglongjmp. Once it goes
I have the following code which ends up in a segmentation fault. for (int
The segmentation fault is caused in the scanner code. The Problem: Using GDB to
I'd have expected the following code to yield a segmentation fault (or otherwise UB):

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.