remove memory leak
This commit is contained in:
parent
1f53f2d5ae
commit
e6ea52bc42
1 changed files with 26 additions and 28 deletions
|
@ -200,6 +200,32 @@ static void NORETURN do_exit(int arg) {
|
|||
task_t* curr_task = per_core(current_task);
|
||||
uint32_t flags, core_id, fd, status;
|
||||
|
||||
if(curr_task->fildes_table) {
|
||||
for (fd = 0; fd < NR_OPEN; fd++) {
|
||||
if(curr_task->fildes_table[fd] != NULL) {
|
||||
/*
|
||||
* delete a descriptor from the per-process object
|
||||
* reference table. If this is not the last reference to the underlying
|
||||
* object, the object will be ignored.
|
||||
*/
|
||||
if (curr_task->fildes_table[fd]->count == 1) {
|
||||
/* try to close the file */
|
||||
status = close_fs(curr_task->fildes_table[fd]);
|
||||
/* close command failed -> return check = errno */
|
||||
if (BUILTIN_EXPECT(status < 0, 0))
|
||||
kprintf("Task %u was not able to close file descriptor %i. close_fs returned %d", curr_task->id, fd, -status);
|
||||
kfree(curr_task->fildes_table[fd], sizeof(fildes_t));
|
||||
curr_task->fildes_table[fd] = NULL;
|
||||
} else {
|
||||
curr_task->fildes_table[fd]->count--;
|
||||
curr_task->fildes_table[fd] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
//finally the table has to be cleared.
|
||||
kfree(curr_task->fildes_table, sizeof(filp_t)*NR_OPEN);
|
||||
}
|
||||
|
||||
kprintf("Terminate task: %u, return value %d\n", curr_task->id, arg);
|
||||
|
||||
wakeup_blocked_tasks(arg);
|
||||
|
@ -214,34 +240,6 @@ static void NORETURN do_exit(int arg) {
|
|||
kfree((void*) tmp, sizeof(vma_t));
|
||||
}
|
||||
|
||||
for (fd = 0; fd < NR_OPEN; fd++) {
|
||||
if (curr_task->fildes_table[fd] != NULL) {
|
||||
/*
|
||||
* delete a descriptor from the per-process object
|
||||
* reference table. If this is not the last reference to the underlying
|
||||
* object, the object will be ignored.
|
||||
*/
|
||||
if (curr_task->fildes_table[fd]->count == 1) {
|
||||
// kprintf("CLOSE_FS\n");
|
||||
/* try to close the file */
|
||||
// status = close_fs(curr_task->fildes_table[fd]);
|
||||
/* close command failed -> return check = errno */
|
||||
if (BUILTIN_EXPECT(status < 0, 0))
|
||||
kprintf("Task %u was not able to close file descriptor %i. close_fs returned %d", curr_task->id, fd, -status);
|
||||
// kfree(curr_task->fildes_table[fd], sizeof(fildes_t));
|
||||
// curr_task->fildes_table[fd] = NULL;
|
||||
} else {
|
||||
// kprintf("DECREASE REF\n");
|
||||
// curr_task->fildes_table[fd]->count--;
|
||||
// curr_task->fildes_table[fd] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// after closing all file decriptors and cleaning up, the table has to be cleared.
|
||||
if(!curr_task->fildes_table)
|
||||
kfree(curr_task->fildes_table, sizeof(filp_t)*NR_OPEN);
|
||||
|
||||
spinlock_unlock(&curr_task->vma_lock);
|
||||
|
||||
drop_pgd(); // delete page directory and its page tables
|
||||
|
|
Loading…
Add table
Reference in a new issue