Memory deallocation with fork and exec
I have a question about memory deallocation in a program that uses the fork and exec functions in the child process. I do not know how to free the memory if the exec operation is successful, as the corresponding code is never executed. If the exec operation fails, memory deallocation works correctly. My code is as follows: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <wait.h> int main() { int L=50; pid_t pid=fork(); if(pid == 0) { int l=2; ++l; // NULL element char ** v = malloc(sizeof(char **) * l); for(int j=0; j<l-1; j++) { v[j]= malloc(sizeof(char
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.