Fix wild frees and leak of fs in test-conf.

Reported by AddressSanitizer when running test-conf. The `query`,
`result`, and `result_fs` were not initialized to NULL so could result
in a wild free when first initialized.

The `method` was also not initialized to NULL so comparisons could be
made against random data if it had not yet been assigned.

The outer `fs` was never destroyed, but is also not used, so remove.
This commit is contained in:
Ben Wagner 2020-12-10 14:12:05 -05:00
parent d55eaa6b31
commit 5cd11d19df
1 changed files with 4 additions and 5 deletions

View File

@ -158,7 +158,6 @@ static FcBool
run_test (FcConfig *config, json_object *root) run_test (FcConfig *config, json_object *root)
{ {
json_object *tests; json_object *tests;
FcFontSet *fs;
int i, n, fail = 0; int i, n, fail = 0;
if (!json_object_object_get_ex (root, "tests", &tests) || if (!json_object_object_get_ex (root, "tests", &tests) ||
@ -167,15 +166,15 @@ run_test (FcConfig *config, json_object *root)
fprintf (stderr, "W: No test cases defined\n"); fprintf (stderr, "W: No test cases defined\n");
return FcFalse; return FcFalse;
} }
fs = FcFontSetCreate ();
n = json_object_array_length (tests); n = json_object_array_length (tests);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
json_object *obj = json_object_array_get_idx (tests, i); json_object *obj = json_object_array_get_idx (tests, i);
json_object_iter iter; json_object_iter iter;
FcPattern *query, *result; FcPattern *query = NULL;
FcFontSet *result_fs; FcPattern *result = NULL;
const char *method; FcFontSet *result_fs = NULL;
const char *method = NULL;
if (json_object_get_type (obj) != json_type_object) if (json_object_get_type (obj) != json_type_object)
continue; continue;