Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/libhamcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Beatrici <git@davidebeatrici.dev>2021-05-01 20:24:28 +0300
committerGitHub <noreply@github.com>2021-05-01 20:24:28 +0300
commit79fd4aa6a140222fb186e4966771b19f8e733075 (patch)
treed93efff94c0d4577136e07be40b4bab38748f46b
parent80937d419d4c9e343dfd84710e02c670e550b778 (diff)
parente2b83d6fdc5c45cb563f79397e8965edf11fe41c (diff)
Merge PR #2: Hamcore.c: handle memory allocation error
-rw-r--r--Hamcore.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Hamcore.c b/Hamcore.c
index 04807f7..83a1ade 100644
--- a/Hamcore.c
+++ b/Hamcore.c
@@ -213,6 +213,10 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_
}
COMPRESSED_FILE *compressed_files = calloc(num, sizeof(COMPRESSED_FILE));
+ if (!compressed_files)
+ {
+ return false;
+ }
void *buffer = NULL;
size_t buffer_size = 0;
@@ -277,9 +281,23 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_
const size_t path_size = strlen(relative_path) + 1;
file->Path = malloc(path_size);
+ if (!file->Path)
+ {
+ free(compressed_files);
+ free(buffer);
+ return false;
+ }
+
memcpy(file->Path, relative_path, path_size);
compressed_file->Data = malloc(file->Size);
+ if (!compressed_file->Data)
+ {
+ free(compressed_files);
+ free(buffer);
+ return false;
+ }
+
memcpy(compressed_file->Data, buffer, file->Size);
}