From 2f7b5e0433a58a118c4152b93a4f850d7f6a1467 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Fri, 5 Jul 2019 10:45:19 +0200 Subject: 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 --- src/plugins/influxdb-writer.c | 7 ++++--- 1 file 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'; } } } -- cgit 1.2.3-korg