fix mem leak

This commit is contained in:
xiang.zhou
2024-11-27 14:16:12 +08:00
parent c0e16f41d4
commit d52ee1bbca
2 changed files with 6 additions and 1 deletions
+4
View File
@@ -29,6 +29,7 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <jansson.h>
@@ -246,6 +247,8 @@ static inline char *neu_value_str(neu_type_e type, neu_value_u value)
{
static __thread char str[128] = { 0 };
memset(str, 0, sizeof(str));
switch (type) {
case NEU_TYPE_INT8:
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
@@ -314,6 +317,7 @@ static inline char *neu_value_str(neu_type_e type, neu_value_u value)
char *result = json_dumps(value.json, JSON_REAL_PRECISION(16));
snprintf(str, sizeof(str), "type: %s, value: %s", neu_type_string(type),
result);
free(result);
break;
}
default:
+2 -1
View File
@@ -668,7 +668,8 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
elem->value.value.ptr.ptr = calloc(1, value.value.ptr.length);
memcpy(elem->value.value.ptr.ptr, value.value.ptr.ptr,
value.value.ptr.length);
} else if (value.type == NEU_TYPE_CUSTOM) {
} else if (value.type == NEU_TYPE_CUSTOM ||
value.type == NEU_TYPE_ERROR) {
if (elem->value.type == NEU_TYPE_CUSTOM &&
elem->value.value.json != NULL) {
json_decref(elem->value.value.json);