mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-01-10 17:32:05 +05:30
C: reverse-ramdisk.c: fix memory usage in tf_alloc
This commit is contained in:
parent
9c47cde541
commit
bae1b1a301
@ -13,7 +13,6 @@
|
|||||||
* GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with
|
* GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with
|
||||||
* -DDEBUG to enable debug mode
|
* -DDEBUG to enable debug mode
|
||||||
*
|
*
|
||||||
* To-Do: Test: Fix the bug with invalid next size to reallocate
|
|
||||||
* To-Do: Test: Automate the test verification
|
* To-Do: Test: Automate the test verification
|
||||||
*
|
*
|
||||||
* Author: Intel A80486DX2-66
|
* Author: Intel A80486DX2-66
|
||||||
@ -109,7 +108,17 @@ int tf_alloc(size_t n, size_t type_size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory for the TempFile struct
|
// Allocate/reallocate memory for all TempFiles
|
||||||
|
temp_files = temp_files == NULL ?
|
||||||
|
malloc(sizeof(TempFile))
|
||||||
|
:
|
||||||
|
realloc(temp_files, (num_temp_files + 1) * sizeof(TempFile));
|
||||||
|
if (temp_files == NULL) {
|
||||||
|
LINE_FAIL(-2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate memory for this TempFile
|
||||||
TempFile* temp_file = malloc(sizeof(TempFile));
|
TempFile* temp_file = malloc(sizeof(TempFile));
|
||||||
if (temp_file == NULL) {
|
if (temp_file == NULL) {
|
||||||
LINE_FAIL(-2);
|
LINE_FAIL(-2);
|
||||||
@ -122,16 +131,6 @@ int tf_alloc(size_t n, size_t type_size) {
|
|||||||
temp_file->file_path = strdup(file_path);
|
temp_file->file_path = strdup(file_path);
|
||||||
temp_file->file = file;
|
temp_file->file = file;
|
||||||
|
|
||||||
// Allocate/reallocate memory for the temp_files structure
|
|
||||||
temp_files = temp_files == NULL ?
|
|
||||||
malloc(sizeof(TempFile))
|
|
||||||
:
|
|
||||||
realloc(temp_files, num_temp_files * sizeof(TempFile));
|
|
||||||
if (temp_files == NULL) {
|
|
||||||
LINE_FAIL(-2);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the temp file to the array
|
// Add the temp file to the array
|
||||||
temp_files[num_temp_files++] = *temp_file;
|
temp_files[num_temp_files++] = *temp_file;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user