From 528fc4f72760105875aa6a437d613e7f7d83ad80 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 21 Jan 2024 19:00:03 +0100 Subject: [PATCH] fix memory leak do not allocate void pointer --- src/kds_s2000w_handler.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index b6a75d4..5e54d62 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -35,6 +35,9 @@ void kds_s2000w_handler_get_option(int option, void* value) if(!curl) return; + if (option != 0) + return; + response resp = {0}; CURLU* url_handler = curl_url(); curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session", 0); @@ -44,21 +47,18 @@ void kds_s2000w_handler_get_option(int option, void* value) char* url = NULL; curl_url_get(url_handler, CURLUPART_URL, &url, 0); - if (option == 0) { - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) &resp); - CURLcode result = curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp.code); - - json_object* resObj = json_tokener_parse(resp.data); - json_object* config = json_object_object_get(resObj, "Configuration"); - int* num_options = (int*) value; - num_options = malloc(sizeof(int)); - *num_options = 0; - *num_options = json_object_object_length(config); - } + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) &resp); + CURLcode result = curl_easy_perform(curl); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp.code); + + json_object* resObj = json_tokener_parse(resp.data); + json_object* config = json_object_object_get(resObj, "Configuration"); + int* num_options = (int*) value; + *num_options = 0; + *num_options = json_object_object_length(config); curl_url_cleanup(url_handler); url_handler = NULL; -- 2.39.5