]> granicus.if.org Git - json-c/commitdiff
Add test to check for the memory leak mentioned in issue #781
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sun, 24 Jul 2022 18:59:26 +0000 (18:59 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sun, 24 Jul 2022 18:59:26 +0000 (18:59 +0000)
tests/test_set_value.c

index f51a2a5b672afe7eff29cc62bda8f2c06e8c5389..a8ebbfec79626d708b64518dff4fdce83d5e8d06 100644 (file)
@@ -71,6 +71,14 @@ int main(int argc, char **argv)
        json_object_set_string(tmp, SHORT);
        assert(strcmp(json_object_get_string(tmp), SHORT) == 0);
        assert(strcmp(json_object_to_json_string(tmp), "\"" SHORT "\"") == 0);
+
+       // Set an empty string a couple times to try to trigger
+       // a case that used to leak memory.
+       json_object_set_string(tmp, "");
+       json_object_set_string(tmp, HUGE);
+       json_object_set_string(tmp, "");
+       json_object_set_string(tmp, HUGE);
+
        json_object_put(tmp);
        printf("STRING PASSED\n");