From ad1036d7810b19f23211f86e88ba3ba870ba6992 Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Thu, 6 Sep 2018 09:20:13 +0900 Subject: [PATCH] [SATIZENVUL-1601] Fix incorrect use of free Change-Id: I33dd481d6cad29ffe4013d480530ac8b46441cb0 Signed-off-by: Cheoleun Moon --- packaging/capi-network-http.spec | 2 +- src/http_transaction.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packaging/capi-network-http.spec b/packaging/capi-network-http.spec index 99b6f3f..38cf333 100644 --- a/packaging/capi-network-http.spec +++ b/packaging/capi-network-http.spec @@ -1,6 +1,6 @@ Name: capi-network-http Summary: Http Framework -Version: 0.0.35 +Version: 0.0.36 Release: 0 Group: System/Network License: Apache-2.0 diff --git a/src/http_transaction.c b/src/http_transaction.c index 6894c05..ef4252e 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -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; -- 2.34.1