From 2a7b3f4e2ae09d665f9783030323dfb1a4c5ee9f Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 2 Apr 2020 15:51:25 +0200 Subject: Add missing free functions to C API This patch adds two missing free functions, NK_free_config and NK_free_password_safe_slot_status, to enable memory-safe use of the C API. Fixes #173. --- NK_C_API.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index d5c54a3..c4cb448 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -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 -- cgit v1.2.1