Skip to content

Obsolete code in cJSON_InitHooks? #243

@MattStillerman

Description

@MattStillerman

cJSON_InitHooks will reset the three global hook functions to malloc, free, and realloc. But, just a few lines above the hooks are initialized to internal_malloc, internal_free, and internal_realloc.

If a user program were to call cJSON_InitHooks(NULL), then the three global hook functions will not be reset to their original values, but to this potentially incorrect set of values.

I should also point out that when cJSON_InitHooks is used to set the allocate and deallocate hooks, then if the supplied value for either of those is NULL, the function will set the corresponding hook to malloc or free rather than their internal_ forms.

BTW, there is no way to set the reallocate hook to anything except realloc (should be internal_realloc) or NULL. Would be nice to be able to set this to some custom function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions