PeachOS icon indicating copy to clipboard operation
PeachOS copied to clipboard

Memory leak at elf_file pointer when process_load_elf function calls elf_load and elf_load fails because of some reason

Open auyargicoglu opened this issue 1 year ago • 0 comments

Memory leak at elf_file pointer when process_load_elf function calls elf_load and elf_load fails because of some reason

task/process.c

static int process_load_elf(const char* filename, struct process* process)

{

int res = 0;

struct elf_file* elf_file = 0;

**res = elf_load(filename, &elf_file); // 1 call elf_load for an invalid file**

if (ISERR(res))

{

    **goto out; // 5 allocated memory leaks!!!!**

}



process->filetype = PROCESS_FILETYPE_ELF;

process->elf_file = elf_file;

out:

return res;

}

loader/formats/elfloader.c

int elf_load(const char* filename, struct elf_file** file_out)

{

**struct elf_file* elf_file = kzalloc(sizeof(struct elf_file));  //2 mem allocated**

int fd = 0;



**int res = fopen(filename, "r"); // 3 function fails with 0**

if (res <= 0)

{

    res = -EIO;

    **goto out; // 4 later returns error, but elf_file points to an allocated memory**

}

......

auyargicoglu avatar Oct 09 '24 13:10 auyargicoglu