]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
free explicit response with null
authorBastian Dehn <hhaalo@arcor.de>
Sun, 28 Jan 2024 19:30:47 +0000 (20:30 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 28 Jan 2024 19:30:47 +0000 (20:30 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_handler.c

index 07d21a1b2340c594a2f1f2cac97f797aa46286dc..06895339eab7091ff90ba69262d673d067dd5fb7 100644 (file)
@@ -33,6 +33,9 @@ response* kds_s2000w_client_response_init()
 
 void kds_s2000w_client_response_free(response* response)
 {
+       if (response == NULL)
+               return;
+
        free(response->data);
        response->data = NULL;
        free(response);
index 7aba359336355c6e935b700b2fa1a4586ebaecf7..9ea8c5488fe6cbb62847f1f1cdb9b94eaead3f69 100644 (file)
@@ -70,6 +70,8 @@ current_state* kds_s2000w_handler_open()
 
        json_object_put(resObj);
        resObj = NULL;
+       kds_s2000w_client_response_free(resp);
+       resp = NULL;
 
        printf("sessionid: %li\n", state->sessionid);
        return state;
@@ -87,6 +89,7 @@ void kds_s2000w_handler_close()
        json_object_put(resObj);
        resObj = NULL;
        kds_s2000w_client_response_free(resp);
+       resp = NULL;
 }
 
 current_state* kds_s2000w_handler_current_state()
@@ -99,6 +102,7 @@ void kds_s2000w_handler_get_option(int option, void* value)
        json_object* value_object = NULL;
        switch(option) {
                case 0:
+                       resp = kds_s2000w_client_response_init();
                        int result = kds_s2000w_client_get_option(state->sessionid, resp);
                        resObj = json_tokener_parse(resp->data);
                        config = json_object_object_get(resObj, "Configuration");
@@ -113,6 +117,8 @@ void kds_s2000w_handler_get_option(int option, void* value)
 
                        int* int_value_ptr = (int*) value;
                        *int_value_ptr = json_object_object_length(config) + 3;
+                       kds_s2000w_client_response_free(resp);
+                       resp = NULL;
                        break;
                case 2:
                        value_object = json_object_object_get(config, "DPI");
@@ -304,11 +310,14 @@ void kds_s2000w_handler_set_option(int option, void* value)
                        break;
        }
 
-       const char* json_string = json_object_to_json_string_ext(resObj, JSON_C_TO_STRING_PLAIN);
-       resp->data = (char*) json_string;
-       resp->size = sizeof(char) * strlen(json_string);
-       resp->code = 0;
-       kds_s2000w_client_set_option(state->sessionid, resp);
+       // TODO: send request
+       // const char* json_string = json_object_to_json_string_ext(resObj, JSON_C_TO_STRING_PLAIN);
+       // resp = kds_s2000w_client_response_init();
+       // resp->data = (char*) json_string;
+       // resp->size = sizeof(char) * strlen(json_string);
+       // resp->code = 0;
+       // kds_s2000w_client_set_option(state->sessionid, resp);
+       // kds_s2000w_client_response_free(resp);
 }
 
 void kds_s2000w_handler_set_option_auto(int option)