aboutsummaryrefslogtreecommitdiffstats
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-07-05 15:25:38 +0200
commit2f7b5e0433a58a118c4152b93a4f850d7f6a1467 (patch)
treea8e9a31f6e7529c72ce77fab8c0e670e7daa837d
parent8d55c66257e0b949ee6daa9dc63f287f4ab9df40 (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>
-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 04c94bd..79eb72c 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';
}
}
}