oc_sdi: minor cleanup
@@ -50,8 +50,10 @@ oc_sec_sdi_free(void)
}
for (device = 0; device < oc_core_get_num_devices(); device++) {
+ if (oc_string_len(sdi[device].name) > 0) {
oc_free_string(&(sdi[device].name));
}
+ }
#ifdef OC_DYNAMIC_ALLOCATION
if (sdi) {
@@ -69,8 +71,9 @@ oc_sec_sdi_default(size_t device)
sdi[device].priv = false;
memset(&(sdi[device].uuid), 0, sizeof(oc_uuid_t));
+ if (oc_string_len(sdi[device].name) > 0) {
oc_free_string(&sdi[device].name);
- oc_new_string(&sdi[device].name, "", 0);
+ }
oc_sec_dump_sdi(device);
}
@@ -102,7 +105,9 @@ oc_sec_decode_sdi(oc_rep_t *rep, bool from_storage, size_t device)
return false;
}
+ if (oc_string_len(s->name) > 0) {
oc_free_string(&s->name);
+ }
oc_new_string(&s->name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
suc = true;
