diff options
| author | liuwentan <[email protected]> | 2023-12-29 11:59:07 +0800 |
|---|---|---|
| committer | liuwentan <[email protected]> | 2023-12-29 11:59:07 +0800 |
| commit | 21d1d573ad84bf782f288f25cda25fe0f0aa2e15 (patch) | |
| tree | b5798418df182edb0667d2aeadbae9fbbbc4996e | |
| parent | c131eeda82a32b0db6f4dc56adcc5e5d6815c9fb (diff) | |
[HTTP_DECODER]memory leak bugfix
| -rw-r--r-- | src/http_decoder/http_decoder.c | 2 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_string.c | 7 | ||||
| -rw-r--r-- | test/http_decoder/http_decoder_gtest.cpp | 1 |
3 files changed, 9 insertions, 1 deletions
diff --git a/src/http_decoder/http_decoder.c b/src/http_decoder/http_decoder.c index c2d1c55..1bfbcad 100644 --- a/src/http_decoder/http_decoder.c +++ b/src/http_decoder/http_decoder.c @@ -232,6 +232,8 @@ static void http_event_handler(enum http_event event, case HTTP_EVENT_RES_BODY_END: break; case HTTP_EVENT_RES_END: + http_decoder_result_queue_inc_res_index(queue); + http_decoder_result_queue_gc(queue, queue->res_index); break; default: assert(0); diff --git a/src/http_decoder/http_decoder_string.c b/src/http_decoder/http_decoder_string.c index bd24253..ce7c2db 100644 --- a/src/http_decoder/http_decoder_string.c +++ b/src/http_decoder/http_decoder_string.c @@ -68,7 +68,12 @@ void http_decoder_string_cache(struct http_decoder_string *rstr) switch (rstr->state) { case STRING_STATE_REFER: if (rstr->refer.str_len > 0) { - rstr->cache.str = (char *)realloc(rstr->cache.str, rstr->cache.str_len + rstr->refer.str_len); + if (NULL == rstr->cache.str) { + rstr->cache.str = CALLOC(char, rstr->refer.str_len + 1); + } else { + rstr->cache.str = REALLOC(char, rstr->cache.str, rstr->cache.str_len + rstr->refer.str_len + 2); + } + memcpy(rstr->cache.str + rstr->cache.str_len, rstr->refer.str, rstr->refer.str_len); rstr->cache.str_len += rstr->refer.str_len; diff --git a/test/http_decoder/http_decoder_gtest.cpp b/test/http_decoder/http_decoder_gtest.cpp index 17f45ab..67bb924 100644 --- a/test/http_decoder/http_decoder_gtest.cpp +++ b/test/http_decoder/http_decoder_gtest.cpp @@ -129,6 +129,7 @@ void res_line_to_json(cJSON *ctx, struct http_response_line *res_line) void http_header_to_json(cJSON *ctx, struct http_header *header) { char key[MAX_KEY_STR_LEN] = {0}; + snprintf(key, header->key.str_len + 1, "%s", header->key.str); if (cJSON_HasObjectItem(ctx, key) == FALSE) { |
