From 31746105e83a25e30697e5aa0b036010f82be88e Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Mon, 4 Sep 2023 02:10:50 -0400 Subject: [PATCH] Simplify goto flow --- src/win32_monitor.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/win32_monitor.c b/src/win32_monitor.c index 830f432a..2111c947 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -70,7 +70,7 @@ static char * getAccurateMonitorName(const WCHAR *deviceName) { rc = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount); if (rc != ERROR_SUCCESS) - goto GET_ACCURATE_MONITOR_NAME_FAILURE; + goto EARLY_ABORT_ACCURATE_MONITOR_NAME; free(paths); free(modes); @@ -78,7 +78,7 @@ static char * getAccurateMonitorName(const WCHAR *deviceName) paths = (DISPLAYCONFIG_PATH_INFO *) malloc(sizeof (DISPLAYCONFIG_PATH_INFO) * pathCount); modes = (DISPLAYCONFIG_MODE_INFO *) malloc(sizeof (DISPLAYCONFIG_MODE_INFO) * modeCount); if ((paths == NULL) || (modes == NULL)) - goto GET_ACCURATE_MONITOR_NAME_FAILURE; + goto EARLY_ABORT_ACCURATE_MONITOR_NAME; rc = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths, &modeCount, modes, 0); } while (rc == ERROR_INSUFFICIENT_BUFFER); @@ -122,15 +122,11 @@ static char * getAccurateMonitorName(const WCHAR *deviceName) } } +// We don't free retval when aborting because currently we goto when retval == NULL +EARLY_ABORT_ACCURATE_MONITOR_NAME: free(paths); free(modes); return retval; - -GET_ACCURATE_MONITOR_NAME_FAILURE: - free(retval); - free(paths); - free(modes); - return NULL; } // Callback for EnumDisplayMonitors in createMonitor