diff options
-rw-r--r-- | NK_C_API.cc | 8 | ||||
-rw-r--r-- | NK_C_API.h | 14 | ||||
-rw-r--r-- | unittest/test_memory.c | 4 |
3 files changed, 24 insertions, 2 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index 1d3fa3a..0b7f5f7 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -226,6 +226,10 @@ extern "C" { }); } + NK_C_API void NK_free_config(uint8_t* config) { + delete[] config; + } + NK_C_API enum NK_device_model NK_get_device_model() { auto m = NitrokeyManager::instance(); @@ -448,6 +452,10 @@ extern "C" { } + NK_C_API void NK_free_password_safe_slot_status(uint8_t* status) { + delete[] status; + } + NK_C_API uint8_t NK_get_user_retry_count() { auto m = NitrokeyManager::instance(); return get_with_result([&]() { @@ -451,6 +451,7 @@ extern "C" { /** * Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and is enabled PIN protected OTP + * The return value must be freed using NK_free_config. * @see NK_write_config * @return uint8_t general_config[5]: * uint8_t numlock; @@ -462,6 +463,12 @@ extern "C" { */ NK_C_API uint8_t* NK_read_config(); + /** + * Free a value returned by NK_read_config. May be called with a NULL + * argument. + */ + NK_C_API void NK_free_config(uint8_t* config); + //OTP /** @@ -634,10 +641,17 @@ extern "C" { /** * Get password safe slots' status + * The return value must be freed using NK_free_password_safe_slot_status. * @return uint8_t[16] slot statuses - each byte represents one slot with 0 (not programmed) and 1 (programmed) */ NK_C_API uint8_t * NK_get_password_safe_slot_status(); + /** + * Free a value returned by NK_get_password_safe_slot_status. May be + * called with a NULL argument. + */ + NK_C_API void NK_free_password_safe_slot_status(uint8_t* status); + /** * Get password safe slot name * @param slot_number password safe slot number, slot_number<16 diff --git a/unittest/test_memory.c b/unittest/test_memory.c index 34ea7d5..20b11b2 100644 --- a/unittest/test_memory.c +++ b/unittest/test_memory.c @@ -44,7 +44,7 @@ int main() { uint8_t *config = NK_read_config(); if (config == NULL) return 1; - free(config); + NK_free_config(config); result = NK_enable_password_safe("123456"); if (result != 0) @@ -54,7 +54,7 @@ int main() { if (slot_status == NULL) { return 1; } - free(slot_status); + NK_free_password_safe_slot_status(slot_status); NK_logout(); |