mirror of
https://github.com/emqx/neuron.git
synced 2026-10-19 05:51:27 +08:00
fix mem leak
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user