Nitrokey / libnitrokey

Communicate with Nitrokey devices in a clean and easy manner
https://nitrokey.com/
GNU Lesser General Public License v3.0
65 stars 34 forks source link

Pointer returned by NK_read_config cannot be deleted properly #173

Closed robinkrahl closed 4 years ago

robinkrahl commented 4 years ago

NK_read_config returns a pointer to an array that is allocated using new[] (in duplicate_vector_and_clear), so it should be deleted using delete[]. But the user of the C API typically will only have access to free, which should not be used in this case (see e. g. the ISO C++ FAQ). I suggest to add a new NK_free_config function that calls delete[] on a config array.

Alternatively, the NK_read_config function could be removed as the same data is returned by the NK_get_status function.

robinkrahl commented 4 years ago

Another alternative would be to use calloc to allocate the array instead of new[]. Then the user could just call free.

robinkrahl commented 4 years ago

I just noticed that NK_get_password_safe_slot_status has the same problem.