akheron / jansson

C library for encoding, decoding and manipulating JSON data
http://www.digip.org/jansson/
Other
3.02k stars 807 forks source link

[question] multiple usage of json_set_alloc_funcs #669

Closed paolostivanin closed 6 days ago

paolostivanin commented 8 months ago

Hello, at the program startup, I set the following custom alloc funcs:

json_set_alloc_funcs (gcry_malloc_secure, gcry_free);

in some other part of my program I would need to use other alloc funcs (without secure memory). Would it be OK to call again json_set_alloc_funcs or could this screw things up for stuff that's still in memory using the previous call?

Example:

What do you think?

Thanks!

akheron commented 6 days ago

The alloc funcs are only using when allocating and deallocating memory. They are stored as function pointers in global variables. Your use case is fine as long as the specific function doesn't e.g. try to free a json structure that was created with the previous alloc functions.