camgunz / cmp

An implementation of the MessagePack serialization format in C / msgpack.org[C]
http://msgpack.org
MIT License
340 stars 78 forks source link

A minor bug in test.c #44

Closed IronBug closed 6 years ago

IronBug commented 7 years ago

In test.c file there's a memory allocation error when str8 is freed and then used in test_string case.

I offer the patch:

diff --git a/test/test.c b/test/test.c
index 7b57609..cb92928 100644
--- a/test/test.c
+++ b/test/test.c
@@ -2783,7 +2783,6 @@ static void test_string(void **state) {
   assert_true(cmp_write_str_v4(&cmp, str16, 300));
   assert_true(cmp_write_str_v4(&cmp, str32, 70000));

-  free(str8);
   free(str16);
   free(str32);

@@ -2817,6 +2816,8 @@ static void test_string(void **state) {
   assert_true(cmp_read_object(&cmp, &obj));
   assert_false(cmp_object_to_str(&cmp, &obj, str8, 5));
   assert_true(cmp_object_to_str(&cmp, &obj, str8, 6));
+
+  free(str8);
 }
camgunz commented 6 years ago

Hi! Sorry I guess my GitHub notification settings need a little work. Thanks for this; you're right there's a bug. I'm a little surprised this wasn't caught by things. I'll apply this patch and see if I can get the infrastructure to catch this.

camgunz commented 6 years ago

Fixed up; thanks again!