Revision 993
Free's shared memory in the core file upon error in forking or error in attaching to shared memory
robot.c | ||
---|---|---|
68 | 68 |
r->shared = (RobotShared*)shmat(r->sharedMemID, NULL, 0); |
69 | 69 |
|
70 | 70 |
if(!(r->shared)) |
71 |
{ |
|
72 |
// TODO: do we have to free the shared memory? |
|
71 |
{ |
|
72 |
//Free shared memory region |
|
73 |
if (!shmctl(r->sharedMemID, IPC_RMID, NULL)) |
|
74 |
fprintf(stderr, "Failed to free shared memory.\n"); |
|
75 |
|
|
73 | 76 |
fprintf(stderr, "Error attaching memory to parent.\n"); |
74 | 77 |
return -1; |
75 | 78 |
} |
... | ... | |
81 | 84 |
|
82 | 85 |
if((pid = fork()) < 0) |
83 | 86 |
{ |
84 |
// TODO: do we have to free the shared memory? |
|
87 |
|
|
88 |
//Free Shared Memory Region |
|
89 |
if (!shmdt(r->shared)) |
|
90 |
fprintf(stderr, "Failed to free shared memory.\n"); |
|
91 |
|
|
92 |
if (!shmctl(r->sharedMemID, IPC_RMID, NULL)) |
|
93 |
fprintf(stderr, "Failed to free shared memory.\n"); |
|
94 |
|
|
85 | 95 |
r->id = 0; |
86 | 96 |
fprintf(stderr, "Failed to fork robot process.\n"); |
87 | 97 |
return -1; |
... | ... | |
139 | 149 |
if (r->id == 0) |
140 | 150 |
return -1; |
141 | 151 |
|
142 |
if (!shmdt(r->shared))
|
|
152 |
if (!shmdt(r->shared))
|
|
143 | 153 |
{ |
144 | 154 |
fprintf(stderr, "Failed to free shared memory.\n"); |
145 | 155 |
return -1; |
Also available in: Unified diff