summaryrefslogtreecommitdiffstats
path: root/src/plugins/influxdb-writer.c
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2019-07-05 10:45:19 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2019-08-01 17:45:11 +0200
commitce3b77ec68974696be19034905293fa8c88f70a0 (patch)
tree4cbf5ccd618e7197f5765bcc28e9852adbf236c1 /src/plugins/influxdb-writer.c
parent95ea5e667f0127b504323c3ea53805dc71e58f66 (diff)
Improve buf allocation for curl requests
Use alloca to allocate write buffer used to send curl requests. Better solution would be to allocate one time (using malloc) and then realloc if needed (IOW current buf size is not suffisant). Change-Id: I9c2ea8628025edd76964993e11d693f1b945045b Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'src/plugins/influxdb-writer.c')
-rw-r--r--src/plugins/influxdb-writer.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index a560cb7..ddf8fc6 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -95,10 +95,11 @@ CURL* make_curl_write_post(afb_api_t apiHandle, const char* url, json_object* me
CURL* curl = NULL;
size_t lpd = 0, len_write = 0, i = 0;
char** post_data;
- char write[URL_MAXIMUM_LENGTH] = "";
+ char* write = alloca(URL_MAXIMUM_LENGTH); // FIXME: better to use malloc and relloc bigger when needed
struct series_t* serie = NULL;
json_object* metricsArrayJ = NULL;
+ write[0] = '\0';
if (json_object_is_type(metricsJ, json_type_array)) {
lpd = json_object_array_length(metricsJ);
@@ -125,8 +126,8 @@ CURL* make_curl_write_post(afb_api_t apiHandle, const char* url, json_object* me
len_write = format_write_args(write, serie);
if (len_write > 0) {
post_data[i] = malloc(len_write + 1);
- strcpy(post_data[i], write);
- memset(write, 0, len_write);
+ strncpy(post_data[i], write, len_write+1);
+ write[0] = '\0';
}
}
}