From 34f818196ef2e1b523fe1170efb412e09a0d5acb Mon Sep 17 00:00:00 2001 From: youmetme <321640253@qq.com> Date: Sat, 2 Nov 2024 17:31:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=86=85=E5=AD=98=E5=88=86=E9=85=8D?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interceptor/logging-interceptor-substr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/interceptor/logging-interceptor-substr.c b/src/interceptor/logging-interceptor-substr.c index c7deb19..7610ca9 100644 --- a/src/interceptor/logging-interceptor-substr.c +++ b/src/interceptor/logging-interceptor-substr.c @@ -31,7 +31,7 @@ static bool kmp_search(char *substr, char *master) { int j = 0; int substrlen = strlen(substr); int masterlen = strlen(master); - int *next = (int *)malloc(sizeof(int) * substrlen + 1); + int *next = (int *)malloc(sizeof(int) * (substrlen + 1)); get_next(substr, next); while (i < masterlen && j < substrlen) { @@ -80,19 +80,22 @@ static bool _disposeSubstring(char *level, const char *message, ...) { * @description : 完成拦截器自我释放内存 */ static void _freeSubstring(log_Interceptor *interceptor) { - int sum = 0; - while (G_keywords[sum] != NULL) { + if (G_keywords!=NULL) { + int sum = 0; + while (G_keywords[sum] != NULL) { + free(G_keywords[sum]); + sum++; + } free(G_keywords[sum]); - sum++; + free(G_keywords); + G_keywords = NULL; } - free(G_keywords); - G_keywords = NULL; if (interceptor->handler != NULL) { interceptor->handler->_free(interceptor->handler); } - - free(interceptor); + + if(interceptor!=NULL)free(interceptor); } /**