1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-05-31 08:31:41 +05:30

reverse-ramdisk.c: reduce memory overhead

This commit is contained in:
2024-07-30 17:40:45 +03:00
parent 9c44ce5af2
commit 3f4c38c1e1

View File

@@ -123,27 +123,26 @@ int tf_alloc(size_t n, size_t type_size) {
:
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));
if (temp_file == NULL) {
free(file_path);
#if IS_POSIX
close(file);
#else
fclose(file);
#endif
LINE_FAIL(-2);
return -1;
}
// Assign the ID, file path, file handler
temp_file->locked = false;
temp_file->ID = num_temp_files;
temp_file->file_path = strdup(file_path);
temp_file->file = file;
temp_files[num_temp_files].locked = false;
temp_files[num_temp_files].ID = num_temp_files;
temp_files[num_temp_files].file_path = file_path;
temp_files[num_temp_files].file = file;
// Add the temp file to the array
temp_files[num_temp_files++] = *temp_file;
// Increment the number of temp files
num_temp_files++;
return temp_file->ID;
return temp_files[num_temp_files - 1].ID;
}
int tf_free(int ID) {