]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
fix memory leak do not allocate void pointer
authorBastian Dehn <hhaalo@arcor.de>
Sun, 21 Jan 2024 18:00:03 +0000 (19:00 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 21 Jan 2024 18:00:03 +0000 (19:00 +0100)
src/kds_s2000w_handler.c

index b6a75d4cea06cb291ea6f1fac0d83cc6a3a3537d..5e54d627a9777ad930ab0b4eae48cfaaca179e38 100644 (file)
@@ -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;