-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mpack crashes without a matching call to mpack_complete_* #88
Comments
Thanks for the bug report. It should be fixed now. The writer will clean up properly when destroyed with an open builder. I don't have great tests for it at the moment (or for any of the builder code for that matter.) This will hopefully improve later. Thanks for using the builder, and please report any more bugs you find. If you run your test with the latest code, the call to // finish writing
mpack_error_t error = mpack_writer_destroy(&writer);
if (error != mpack_ok) {
fprintf(stderr, "An error occurred encoding the data! %s (%i)\n",
mpack_error_to_string(error), error);
return 1;
} This will now print:
Valgrind will report no leaks or other problems. If you additionally build with
Valgrind will print the abort and may also print leaks since it doesn't clean up when it aborts. You can build a new amalgamation package from the latest source with |
Thanks for fixing this. I'd just push back a bit on this description. IIUC, an error can occur doing the serialization (e.g. an I/O error), that will short-circuit |
Hmm. You're partially right. An error can't happen from I/O; it can only happen from a malloc failure. When a builder is open all writes are diverted to a buffer because we can't output anything until we figure out the size of the container being built. If a malloc does fail though, it will indeed flag an error and short circuit subsequent calls to There is another bug that can occur though if the caller is using longjmp for error handling. The I/O happens in I'm not sure of the proper fix here yet, but most likely I will just defer the callback until after the writer has walked all its pages. The reader does something similar when reading into an allocation. In any case I am reopening this issue. I need to fix this longjmp bug, plus I need a lot more unit tests to make sure these bugs don't crop up again. At the very least the builder needs tests to make sure it handles any malloc failure properly. |
This fixes a memory leak (and possible crash) that could occur if the user longjmps out of the error handler while a builder is being resolved. See #88
Taking the example from the README:
This makes it impossible to use error chaining. In this case, I omitted the call to
mpack_complete_map
altogether, but it can also be skipped because of an earlier error. In fact, it's a problem even with:The text was updated successfully, but these errors were encountered: