From 599387d2446bc622d27fd13291ad12b365926c49 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 24 Feb 2017 20:49:36 +0200 Subject: [PATCH] Add test coverage for calling pb_release() on a message with callback fields. --- tests/alltypes_callback/SConscript | 6 +++++- tests/alltypes_callback/decode_alltypes_callback.c | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/alltypes_callback/SConscript b/tests/alltypes_callback/SConscript index a241f24e..1cef3972 100644 --- a/tests/alltypes_callback/SConscript +++ b/tests/alltypes_callback/SConscript @@ -1,6 +1,6 @@ # Test the AllTypes encoding & decoding using callbacks for all fields. -Import("env") +Import("env", "malloc_env") c = Copy("$TARGET", "$SOURCE") env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) @@ -21,3 +21,7 @@ env.RunTest("optionals.output", enc, ARGS = ['1']) env.RunTest("optionals.refdecout", [refdec, "optionals.output"], ARGS = ['1']) env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) +# Try with malloc support also +mallocbin = malloc_env.Object("decode_with_malloc.o", "decode_alltypes_callback.c") +mallocdec = malloc_env.Program("decode_with_malloc", [mallocbin, "alltypes.pb.o", "$COMMON/pb_decode_with_malloc.o", "$COMMON/pb_common_with_malloc.o", "$COMMON/malloc_wrappers.o"]) +env.RunTest("decode_with_malloc.output", [mallocdec, "encode_alltypes_callback.output"]) diff --git a/tests/alltypes_callback/decode_alltypes_callback.c b/tests/alltypes_callback/decode_alltypes_callback.c index 4366cf3f..1d8c268c 100644 --- a/tests/alltypes_callback/decode_alltypes_callback.c +++ b/tests/alltypes_callback/decode_alltypes_callback.c @@ -395,7 +395,14 @@ bool check_alltypes(pb_istream_t *stream, int mode) alltypes.oneof_msg1.arg = &oneof_msg1; } - return pb_decode(stream, AllTypes_fields, &alltypes); + bool status = pb_decode(stream, AllTypes_fields, &alltypes); + +#ifdef PB_ENABLE_MALLOC + /* Just to check for any interference between pb_release() and callback fields */ + pb_release(AllTypes_fields, &alltypes); +#endif + + return status; } int main(int argc, char **argv) -- 2.16.6