From 9c4c3fc89943bc0180b4db3ee4f2c68ef19a68cb Mon Sep 17 00:00:00 2001 From: LoaD Accumulator Date: Mon, 11 Sep 2023 10:57:16 -0400 Subject: [PATCH] Fixes issue #33 related to a memory issue, and format some code. (#35) Fixes #33. Co-authored-by: LoaD Accumulator Reviewed-on: https://git.telodendria.io/Telodendria/telodendria/pulls/35 Co-authored-by: LoaD Accumulator Co-committed-by: LoaD Accumulator --- src/HttpRouter.c | 8 ++++++-- src/Str.c | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/HttpRouter.c b/src/HttpRouter.c index 87ddae0..bd06c64 100644 --- a/src/HttpRouter.c +++ b/src/HttpRouter.c @@ -196,7 +196,7 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) char *pathPart; char *tmp; HttpRouteFunc *exec = NULL; - Array *matches; + Array *matches = NULL; size_t i; int retval; @@ -254,14 +254,18 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) { /* pmatch[0] is the whole string, not the first * subexpression */ + char * substr; + regmatch_t cpmatch; for (i = 1; i < REG_MAX_SUB; i++) { + cpmatch = pmatch[i]; + substr = StrSubstr(pathPart, cpmatch.rm_so, cpmatch.rm_eo); if (pmatch[i].rm_so == -1) { break; } - ArrayAdd(matches, StrSubstr(pathPart, pmatch[i].rm_so, pmatch[i].rm_eo)); + ArrayAdd(matches, substr); } } } diff --git a/src/Str.c b/src/Str.c index 98dea0b..2f4c665 100644 --- a/src/Str.c +++ b/src/Str.c @@ -147,7 +147,6 @@ StrSubstr(const char *inStr, size_t start, size_t end) } len = end - start; - outStr = Malloc(len + 1); if (!outStr) {