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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:14:55+00:00 2026-05-23T20:14:55+00:00

Assume that the function func has bugs so that it leaks memory. pid_t childPid;

  • 0

Assume that the function func has bugs so that it leaks memory.

pid_t childPid;
int status;
childPid = fork();
if (childPid == -1)
  errExit("fork");
if (childPid == 0) /* Child calls func() and */
  exit(func(arg)); /* uses return value as exit status */

/* Parent waits for child to terminate. It can determine the
   result of func() by inspecting 'status'. */
if (wait(&status) == -1)
  errExit("wait");

Question 1>
If a program leaks memory, after the program exits in the end, does it still leak memory or system will collect all memory allocated by the program and there is no more leaked memory?

Question 2>
After the parent process calls the wait, how is the leaked memory caused by the func in child process?

  • 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-23T20:14:55+00:00Added an answer on May 23, 2026 at 8:14 pm

    If a program leaks memory, after the program exits in the end, does it
    still leak memory or system will collect all memory allocated by the
    program and there is no more leaked memory?

    The system will collect all the memory resources from the child, and there will no longer be any leaked memory from the child process. Also a call to fork() separates the memory space of the parent and child, therefore a leak in the child process will not leak in the parent process unless you call the same buggy function in both.

    After the parent process calls the wait, how is the leaked memory
    caused by the func in child process?

    Calling wait() in the parent, and the child leaking memory really have nothing to-do with each other. The call to wait() in the parent merely causes the parent to block waiting for a signal indicating that a child process has completed. The child will still have to call func() first before it can complete, since it must pass the return value of func() to exit(). Therefore func() can still technically “leak” memory in that it allocates some memory on the heap, but doesn’t clean it up, even though the clean-up actions by the OS takes place almost immediately after func() is called. In other words after the call to exit() is complete, the OS has released the resources used by the child, but func() itself can still fail to free any memory it tried to allocate.

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

Sidebar

Related Questions

Assume that the core project has a base entity and every plugin maybe extends
Do you generally assume that toString() on any given object has a low cost
this is my C++ function that uses a kind of bitwise: int genkey(const unsigned
Assume that i have function called PlaceOrder , which when called inserts the order
I'm having a trouble with my math: Assume that we have a function: F(x,y)
Assume that we have N erlang nodes, running same application. I want to share
Assume that you have a running SQL Server Express instance named (local)\SQLEXPRESS. Its database
I assume that you can't use a JavaScript code snippet to validate if the
I assume that char* = string is the same to char* = new char[6]
I assume that most of the analyzing and tracking is done based on the

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.