1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-27 05:40:17 +05:30

C: reverse-ramdisk.c: tf_free: prevent memory leaks

This commit is contained in:
Intel A80486DX2-66 2024-02-22 21:12:54 +03:00
parent bae1b1a301
commit 3e37f5fb73
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -170,11 +170,13 @@ int tf_free(int ID) {
// Reallocate memory for the temp_files array
if (--num_temp_files > 0) {
DBG_PRINT("num_temp_files = %zu\n", num_temp_files);
if ((temp_files = realloc(temp_files, num_temp_files
* sizeof(TempFile))) == NULL) {
LINE_FAIL(-2);
TempFile* new_temp_files_ptr = realloc(temp_files, num_temp_files *
sizeof(TempFile));
if (new_temp_files_ptr == NULL) {
LINE_FAIL(-3);
return -1;
}
temp_files = new_temp_files_ptr;
}
temp_files[index].locked = false;