Free allocated memories before strdup 21/256721/3
authorCheoleun Moon <chleun.moon@samsung.com>
Mon, 12 Apr 2021 03:10:19 +0000 (12:10 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 12 Apr 2021 03:49:54 +0000 (12:49 +0900)
Change-Id: Iba469a2a10df78a19af1c6107bdea240fdce999b
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
src/vine-data-path.cpp
src/vine-security.cpp

index 7d56749..4a255cf 100755 (executable)
@@ -687,6 +687,8 @@ int vine_data_path_connect(vine_address_family_e addr_family,
                _vine_data_path_create(VINE_DATA_PATH_TYPE_CLIENT, security, ip, port, NULL, event_fd);
        RET_VAL_IF(dp == NULL, VINE_ERROR_OUT_OF_MEMORY, "Out of memory");
 
+       if (dp->addr)
+               free(dp->addr);
        dp->addr = STRDUP(ip);
        dp->port = port;
        dp->connected_cb = callback;
index b9b5201..57e9f80 100755 (executable)
@@ -171,6 +171,8 @@ int _vine_security_set_ca_path(vine_security_h security, const char *ca_path)
        RET_VAL_IF(ca_path == NULL, VINE_ERROR_INVALID_PARAMETER, "ca_path is NULL");
 
        vine_security_s *s = (vine_security_s *)security;
+       if (s->ca_path)
+               free(s->ca_path);
        s->ca_path = STRDUP(ca_path);
 
        return VINE_ERROR_NONE;
@@ -193,6 +195,8 @@ int _vine_security_set_cert_path(vine_security_h security, const char *cert_path
        RET_VAL_IF(cert_path == NULL, VINE_ERROR_INVALID_PARAMETER, "cert_path is NULL");
 
        vine_security_s *s = (vine_security_s *)security;
+       if (s->cert_path)
+               free(s->cert_path);
        s->cert_path = STRDUP(cert_path);
 
        return VINE_ERROR_NONE;
@@ -215,6 +219,8 @@ int _vine_security_set_private_key(vine_security_h security, const char *key_pat
        RET_VAL_IF(key_path == NULL, VINE_ERROR_INVALID_PARAMETER, "key_path is NULL");
 
        vine_security_s *s = (vine_security_s *)security;
+       if (s->key_path)
+               free(s->key_path);
        s->key_path = STRDUP(key_path);
 
        return VINE_ERROR_NONE;
@@ -237,6 +243,8 @@ int _vine_security_set_psk(vine_security_h security, const char *psk)
        RET_VAL_IF(psk == NULL, VINE_ERROR_INVALID_PARAMETER, "psk is NULL");
 
        vine_security_s *s = (vine_security_s *)security;
+       if (s->psk)
+               free(s->psk);
        s->psk = STRDUP(psk);
 
        return VINE_ERROR_NONE;