Commit 0713581d authored by Kishen Maloor's avatar Kishen Maloor

oc_cred: fix leak

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent c9695683
Pipeline #608 failed with stage
in 4 minutes and 47 seconds
...@@ -389,7 +389,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client, ...@@ -389,7 +389,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
if (!subjectuuid) { if (!subjectuuid) {
if (credusage != OC_CREDUSAGE_ROLE_CERT) { if (credusage != OC_CREDUSAGE_ROLE_CERT) {
return -1; goto add_new_cred_error;
} else { } else {
subject.id[0] = '*'; subject.id[0] = '*';
} }
...@@ -439,6 +439,11 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client, ...@@ -439,6 +439,11 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
publicdata_size) == 0)) publicdata_size) == 0))
#endif /* OC_PKI */ #endif /* OC_PKI */
) { ) {
#ifdef OC_PKI
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
#endif /* OC_PKI */
return credid; return credid;
} else { } else {
oc_sec_remove_cred_by_credid(credid, device); oc_sec_remove_cred_by_credid(credid, device);
...@@ -470,6 +475,9 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client, ...@@ -470,6 +475,9 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
publicdata_size == oc_string_len(cred->publicdata.data) && publicdata_size == oc_string_len(cred->publicdata.data) &&
memcmp(publicdata, oc_string(cred->publicdata.data), memcmp(publicdata, oc_string(cred->publicdata.data),
publicdata_size) == 0) { publicdata_size) == 0) {
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
return cred->credid; return cred->credid;
} }
} }
...@@ -486,6 +494,9 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client, ...@@ -486,6 +494,9 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
if ((oc_string_len(roles->publicdata.data) == publicdata_size) && if ((oc_string_len(roles->publicdata.data) == publicdata_size) &&
memcmp(oc_string(roles->publicdata.data), publicdata, memcmp(oc_string(roles->publicdata.data), publicdata,
publicdata_size) == 0) { publicdata_size) == 0) {
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
return roles->credid; return roles->credid;
} }
roles = roles->next; roles = roles->next;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment