[SATIZENVUL-1601] Fix incorrect use of free
[platform/core/api/http.git] / src / http_transaction.c
index 6894c05..ef4252e 100644 (file)
@@ -366,13 +366,14 @@ int _transaction_submit(gpointer user_data)
                gchar *credentials = NULL;
                int credentials_len = 0;
 
-               http_transaction_get_credentials(transaction, &user_name, &password);
+               ret = http_transaction_get_credentials(transaction, &user_name, &password);
+               if (ret != HTTP_ERROR_NONE)
+                       return ret;
+
                credentials_len = sizeof(gchar) * (strlen(user_name) + 1 + strlen(password) + 1);
                credentials = (gchar *)malloc(credentials_len);
                if (credentials) {
                        snprintf(credentials, credentials_len, "%s:%s", (gchar*)user_name, (gchar*)password);
-                       free(user_name);
-                       free(password);
 
                        http_transaction_get_http_auth_scheme(transaction, &auth_scheme);
 
@@ -388,6 +389,8 @@ int _transaction_submit(gpointer user_data)
                        }
                        free(credentials);
                }
+               free(user_name);
+               free(password);
        }
        //LCOV_EXCL_STOP
 
@@ -1160,6 +1163,8 @@ API int http_transaction_get_credentials(http_transaction_h http_transaction, ch
        *password = g_strdup(transaction->password);
        if (*password == NULL) {
                ERR("strdup is failed\n");
+               g_free(*user_name);
+               *user_name = NULL;
                return HTTP_ERROR_OUT_OF_MEMORY;
        }
        return HTTP_ERROR_NONE;