From a4091189b014566dd40d3bb35c22c620e041d1e4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 1 Mar 2024 23:09:21 +0100 Subject: [PATCH 1/2] cleanup: use proper size when allocating string Signed-off-by: Berthold Stoeger --- core/parse-xml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/parse-xml.c b/core/parse-xml.c index ecde453e6..895571c7e 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -2261,7 +2261,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log) /* Recording the starting battery status to extra data */ if (battery_start.volt1) { size_t stringsize = snprintf(NULL, 0, "%dmV (%d%%)", battery_start.volt1, battery_start.percent1) + 1; - char *ptr = malloc(size); + char *ptr = malloc(stringsize); if (ptr) { snprintf(ptr, stringsize, "%dmV (%d%%)", battery_start.volt1, battery_start.percent1); From 805cd550f25f1fb61c86a9a08dd905d4ee0b0ebc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 28 Feb 2024 06:23:26 +0100 Subject: [PATCH 2/2] cleanup: fix memory leak get_local_dir() returns the copy of a c-string. It therefore has to be free()d. Signed-off-by: Berthold Stoeger --- core/git-access.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/git-access.c b/core/git-access.c index 41970e429..fcca4d32a 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -161,7 +161,9 @@ char *get_local_dir(const char *url, const char *branch) static char *move_local_cache(struct git_info *info) { char *old_path = get_local_dir(info->url, info->branch); - return move_away(old_path); + char *new_path = move_away(old_path); + free(old_path); + return new_path; } static int check_clean(const char *path, unsigned int status, void *payload)