diff options
| author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-18 01:59:39 +0200 |
|---|---|---|
| committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-18 09:48:17 +0200 |
| commit | b0963cf8e2b31ac6a60c314bad148cd93d8eaca1 (patch) | |
| tree | a12e648fc0f072215741d2aaa805c207abb83c16 /src/json.c | |
| parent | process: preserve the exit code more (diff) | |
| download | cimple-b0963cf8e2b31ac6a60c314bad148cd93d8eaca1.tar.gz cimple-b0963cf8e2b31ac6a60c314bad148cd93d8eaca1.zip | |
net: don't copy data in struct buf
Diffstat (limited to 'src/json.c')
| -rw-r--r-- | src/json.c | 16 |
1 files changed, 3 insertions, 13 deletions
@@ -17,21 +17,14 @@ #include <stdlib.h> #include <string.h> -char *json_to_string(struct json_object *obj) +const char *json_to_string(struct json_object *obj) { const char *result = json_object_to_json_string(obj); if (!result) { json_errno("json_object_to_json_string"); return NULL; } - - char *_result = strdup(result); - if (!_result) { - log_errno("strdup"); - return NULL; - } - - return _result; + return result; } struct json_object *json_from_string(const char *src) @@ -76,15 +69,11 @@ int json_send(struct json_object *obj, int fd) struct buf *buf = NULL; ret = buf_create_from_string(&buf, str); - free((char *)str); if (ret < 0) return ret; ret = net_send_buf(fd, buf); buf_destroy(buf); - if (ret < 0) - return ret; - return ret; } @@ -103,6 +92,7 @@ struct json_object *json_recv(int fd) goto destroy_buf; destroy_buf: + free((void *)buf_get_data(buf)); buf_destroy(buf); return result; |
