diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-02-10 13:03:25 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-02-10 13:03:25 +0330 |
commit | 6d127edfa0162219c54b10e3496a3e9530f62792 (patch) | |
tree | c70579a2f218f8d233f0f2ef2a1867908a0594f7 /src/utils/file.c | |
parent | 302cc65d3e59937742c18475d63e22c482176fa7 (diff) |
fix double free of code
some clean up
Diffstat (limited to 'src/utils/file.c')
-rw-r--r-- | src/utils/file.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/utils/file.c b/src/utils/file.c index 89ccfa8..921befb 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -30,6 +30,21 @@ void fileDelete() { fileCodes_length = 0; } +void filePush(const char *filePath, char *code) { + if (fileCodes_capacity == fileCodes_length) { + fileCodes_capacity += fileCodes_capacity / 2 + 1; + fileCodes = + a404m_realloc(fileCodes, fileCodes_capacity * sizeof(*fileCodes)); + fileCodes_names = a404m_realloc( + fileCodes_names, fileCodes_capacity * sizeof(*fileCodes_names)); + } + fileCodes[fileCodes_length] = code; + fileCodes_names[fileCodes_length] = + a404m_malloc((strlen(filePath) + 1) * sizeof(**fileCodes_names)); + strcpy(fileCodes_names[fileCodes_length], filePath); + fileCodes_length += 1; +} + char *readWholeFile(const char *filePath) { FILE *file = fopen(filePath, "r"); @@ -48,18 +63,7 @@ char *readWholeFile(const char *filePath) { fclose(file); - if (fileCodes_capacity == fileCodes_length) { - fileCodes_capacity += fileCodes_capacity / 2 + 1; - fileCodes = - a404m_realloc(fileCodes, fileCodes_capacity * sizeof(*fileCodes)); - fileCodes_names = a404m_realloc( - fileCodes_names, fileCodes_capacity * sizeof(*fileCodes_names)); - } - fileCodes[fileCodes_length] = str; - fileCodes_names[fileCodes_length] = - a404m_malloc((strlen(filePath) + 1) * sizeof(**fileCodes_names)); - strcpy(fileCodes_names[fileCodes_length], filePath); - fileCodes_length += 1; + filePush(filePath, str); return str; } |