PeachOS icon indicating copy to clipboard operation
PeachOS copied to clipboard

Memory leak in process.c process_load_for_slot

Open JaihsonK opened this issue 3 years ago • 1 comments

Hi! In PeachOS Master, there is a possible memory leak in process_load_for_slot. Say we get an error on line 500: `res = process_load_data(filename, _process); if (res < 0) { goto out; }

program_stack_ptr = kzalloc(PEACHOS_USER_PROGRAM_STACK_SIZE);
if (!program_stack_ptr) //line 500
{
    res = -ENOMEM;
    goto out;
}`

then process data needs to be freed. But this doesn't happen. As it stands, the out label acknowledges the need to free the data but doesn't do so: `out: if (ISERR(res)) { if (_process && _process->task) { task_free(_process->task); }

   // Free the process data
}`

A better implementation could be: `if (ISERR(res)) { if (_process && _process->task) { task_free(_process->task); }

    // Free the process data
    process_free_program_data(_process);
}`

JaihsonK avatar Dec 09 '22 21:12 JaihsonK

Your correct about the comment and forgetting to free the process data. Clearly I intended to do it and forgot, it will be corrected

Thank you

nibblebits avatar Jan 03 '23 20:01 nibblebits