From 62e78d7d9f57328304566ec01ffbda3d17508710 Mon Sep 17 00:00:00 2001 From: heyanlong Date: Thu, 1 Aug 2019 16:25:12 +0800 Subject: [PATCH] fix write_log bugs --- skywalking.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/skywalking.c b/skywalking.c index c802b15..81a4552 100644 --- a/skywalking.c +++ b/skywalking.c @@ -913,16 +913,20 @@ static char *sky_json_encode(zval *parameter){ php_json_encode(&buf, parameter, (int)options); #endif smart_str_0(&buf); - char *bufs = ZSTR_VAL(buf.s); - smart_str_free(&buf); - return bufs; + if(buf.s != NULL) { + char *bufs = emalloc(strlen(ZSTR_VAL(buf.s)) + 1); + strcpy(bufs, ZSTR_VAL(buf.s)); + smart_str_free(&buf); + return bufs; + } + return NULL; } static void write_log(char *text) { if (application_instance != 0) { // to stream - if(text == NULL) { + if(text == NULL || strlen(text) <= 0) { return; } @@ -948,6 +952,7 @@ static void write_log(char *text) { close(fd); } efree(message); + efree(text); } } -- GitLab