nibblebits / PeachOS

Simple kernel designed for a online course
GNU General Public License v2.0
133 stars 55 forks source link

Memory leak in process.c process_load_for_slot #13

Open JaihsonK opened 1 year ago

JaihsonK commented 1 year ago

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);
}`
nibblebits commented 1 year ago

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