From 2cee5fb36cdf98488422d6c85f0076e3a70a3ca4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 4 Jan 2024 10:15:26 +1000 Subject: [PATCH] test: fix various leaks in the tests --- dix/devices.c | 2 +- include/input.h | 2 ++ test/input.c | 17 +++++++++++++++++ test/list.c | 4 ++++ test/signal-logging.c | 5 ++++- test/test_xkb.c | 8 ++++++++ test/xfree86.c | 7 +++++++ 7 files changed, 43 insertions(+), 2 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index d58f96b47..56b811fa2 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -778,7 +778,7 @@ InitAndStartDevices(void) /** * Free the given device class and reset the pointer to NULL. */ -static void +void FreeDeviceClass(int type, void **class) { if (!(*class)) diff --git a/include/input.h b/include/input.h index 75c7c2df6..fd5b7c4df 100644 --- a/include/input.h +++ b/include/input.h @@ -331,6 +331,8 @@ extern _X_EXPORT Bool InitButtonClassDeviceStruct(DeviceIntPtr /*device */ , extern _X_INTERNAL ValuatorClassPtr AllocValuatorClass(ValuatorClassPtr src, int numAxes); +extern _X_INTERNAL void FreeDeviceClass(int type, void **class); + extern _X_EXPORT Bool InitValuatorClassDeviceStruct(DeviceIntPtr /*device */ , int /*numAxes */ , diff --git a/test/input.c b/test/input.c index e27374db3..34a75fd7f 100644 --- a/test/input.c +++ b/test/input.c @@ -154,6 +154,9 @@ dix_init_valuators(void) assert(axis->scroll.type == SCROLL_TYPE_VERTICAL); assert(axis->scroll.increment == 3.0); assert(axis->scroll.flags == SCROLL_FLAG_NONE); + + FreeDeviceClass(ValuatorClass, (void**)&val); + free(dev.last.scroll); /* sigh, allocated but not freed by the valuator functions */ } /* just check the known success cases, and that error cases set the client's @@ -282,6 +285,7 @@ dix_event_to_core(int type) ev.detail.key = 0; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); x = 1; y = 2; @@ -289,6 +293,7 @@ dix_event_to_core(int type) ev.root_y = y; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); x = 0x7FFF; y = 0x7FFF; @@ -296,6 +301,7 @@ dix_event_to_core(int type) ev.root_y = y; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); x = 0x8000; /* too high */ y = 0x8000; /* too high */ @@ -307,6 +313,7 @@ dix_event_to_core(int type) assert(count == 1); assert(core->u.keyButtonPointer.rootX != x); assert(core->u.keyButtonPointer.rootY != y); + free(core); x = 0x7FFF; y = 0x7FFF; @@ -316,16 +323,19 @@ dix_event_to_core(int type) ev.time = time; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); detail = 1; ev.detail.key = detail; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); detail = 0xFF; /* highest value */ ev.detail.key = detail; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); detail = 0xFFF; /* too big */ ev.detail.key = detail; @@ -338,6 +348,7 @@ dix_event_to_core(int type) ev.corestate = state; rc = EventToCore((InternalEvent *) &ev, &core, &count); test_event(); + free(core); state = 0x10000; /* too big */ ev.corestate = state; @@ -347,6 +358,7 @@ dix_event_to_core(int type) assert(count == 1); assert(core->u.keyButtonPointer.state != state); assert(core->u.keyButtonPointer.state == (state & 0xFFFF)); + free(core); #undef test_event } @@ -1197,6 +1209,7 @@ dix_input_attributes(void) new = DuplicateInputAttributes(orig); assert(memcmp(orig, new, sizeof(InputAttributes)) == 0); + FreeInputAttributes(new); orig->product = xnfstrdup("product name"); new = DuplicateInputAttributes(orig); @@ -1330,6 +1343,7 @@ dix_input_valuator_masks(void) } valuator_mask_free(&mask); + valuator_mask_free(©); assert(mask == NULL); } @@ -1361,6 +1375,9 @@ dix_valuator_mode(void) valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative); for (i = 0; i < num_axes; i++) assert(valuator_get_mode(&dev, i) == Relative); + + FreeDeviceClass(ValuatorClass, (void**)&dev.valuator); + free(dev.last.scroll); /* sigh, allocated but not freed by the valuator functions */ } static void diff --git a/test/list.c b/test/list.c index d51817c21..fee41a538 100644 --- a/test/list.c +++ b/test/list.c @@ -266,6 +266,8 @@ test_nt_list_append(void) i++; } assert(i == 11); + + free(foo); } static void @@ -300,6 +302,8 @@ test_nt_list_insert(void) i++; } assert(i == 11); + + free(foo); } static void diff --git a/test/signal-logging.c b/test/signal-logging.c index 4ba8485fc..97477dcee 100644 --- a/test/signal-logging.c +++ b/test/signal-logging.c @@ -176,13 +176,16 @@ static void logging_format(void) char read_buf[2048]; char *logmsg; uintptr_t ptr; + char *fname = NULL; /* set up buf to contain ".....end" */ memset(buf, '.', sizeof(buf)); strcpy(&buf[sizeof(buf) - 4], "end"); - LogInit(log_file_path, NULL); + fname = (char*)LogInit(log_file_path, NULL); + assert(fname != NULL); assert((f = fopen(log_file_path, "r"))); + free(fname); #define read_log_msg(msg) do { \ msg = fgets(read_buf, sizeof(read_buf), f); \ diff --git a/test/test_xkb.c b/test/test_xkb.c index a13107390..18e37e408 100644 --- a/test/test_xkb.c +++ b/test/test_xkb.c @@ -75,6 +75,8 @@ xkb_get_rules_test(void) assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0); assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0); assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0); + + XkbFreeRMLVOSet(&rmlvo, FALSE); } /** @@ -114,6 +116,7 @@ xkb_set_rules_test(void) assert(strcmp(rmlvo.options, rmlvo_new.options) == 0); XkbFreeRMLVOSet(&rmlvo, FALSE); + XkbFreeRMLVOSet(&rmlvo_new, FALSE); } /** @@ -139,6 +142,7 @@ xkb_set_get_rules_test(void) /* pass 1 */ XkbSetRulesDflts(&rmlvo); + XkbFreeRMLVOSet(&rmlvo, FALSE); XkbGetRulesDflts(&rmlvo); /* Make a backup copy */ @@ -159,12 +163,16 @@ xkb_set_get_rules_test(void) assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0); assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0); + XkbFreeRMLVOSet(&rmlvo, FALSE); XkbGetRulesDflts(&rmlvo); assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0); assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0); assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0); assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0); assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0); + + XkbFreeRMLVOSet(&rmlvo, FALSE); + XkbFreeRMLVOSet(&rmlvo_backup, FALSE); } int diff --git a/test/xfree86.c b/test/xfree86.c index 59e371633..76837d57e 100644 --- a/test/xfree86.c +++ b/test/xfree86.c @@ -63,17 +63,24 @@ xfree86_option_list_duplicate(void) assert(strcmp(val1, v1) == 0); assert(strcmp(val1, val2) == 0); + free(val1); + free(val2); val1 = xf86CheckStrOption(options, o2, "1"); val2 = xf86CheckStrOption(duplicate, o2, "2"); assert(strcmp(val1, v2) == 0); assert(strcmp(val1, val2) == 0); + free(val1); + free(val2); a = xf86FindOption(options, o_null); b = xf86FindOption(duplicate, o_null); assert(a); assert(b); + + xf86OptionListFree(duplicate); + xf86OptionListFree(options); } static void