-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yajl_gen.c, yajl_parser.c, yajl_tree.c: remove alloc failure checks
- the memory allocators must do their own checks -- checking again in the calling code is wasteful and misleading.
- Loading branch information
Showing
3 changed files
with
10 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159bb72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "must do their own check"?
In the above code, if the YA_MALLOC cannot find enough memory, what is it supposed to do?
if g is null, the memset will use an invalid pointer and the program will usually crash instead of gracefully handling this (and log a clean error message). How could YA_MALLOC break the flow, know where to log the error, etc.?
159bb72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the documentation for
yajl_alloc_funcs
says:See
example/parse_config.c
whereassert()
is used to check for allocation failures. Note also that as shown in this example a context pointer can also be included inyajl_alloc_funcs
to allow an application specific response, such as jumping to safer cleanup, logging, and exit. Users could also make use of a pool allocator (with the specific pool being used indicated in another context variable) and then on error jump to a cleanup that aborted the operation, released the whole pool, and potentially allowed the application to return to operation.I will (hopefully soon) be fixing
json_verify.c
andjson_reformat.c
to also do error and leak detection as inparse_config.c
, and I'll probably change the default allocators to at least useassert()
if not directly useabort()
(to avoid-DNDEBUG
).