From 02bb1c2cfadf5028e40d8fd8256f6c78bb74937d Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 26 Nov 2018 12:09:48 +0100 Subject: [PATCH 1/3] Avoid memory leaks on running check_shell_service_success_auto_start on Windows --- bus/dispatch.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bus/dispatch.c b/bus/dispatch.c index 1373ed70..414b64ab 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -4939,6 +4939,11 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, _dbus_test_fatal ("shell success service auto start failed"); _dbus_test_ok ("%s:%s - check_shell_service_success_auto_start", _DBUS_FUNCTION_NAME, filename); +#ifdef DBUS_WIN_FIXME + _dbus_verbose("TODO: Fix memory leaks after running check_shell_service_success_auto_start\n"); + _dbus_sleep_milliseconds (500); +#endif + _dbus_verbose ("Disconnecting foo, bar, and baz\n"); kill_client_connection_unchecked (foo); From ffcaede257e4c9d3906053f114c1a00d6348b870 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 5 Dec 2018 14:59:17 +0100 Subject: [PATCH 2/3] Drop cmake variable DBUS_WIN_FIXME --- bus/dispatch.c | 2 +- cmake/config.h.cmake | 1 - dbus/dbus-memory.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bus/dispatch.c b/bus/dispatch.c index 414b64ab..4ac93fea 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -4939,7 +4939,7 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, _dbus_test_fatal ("shell success service auto start failed"); _dbus_test_ok ("%s:%s - check_shell_service_success_auto_start", _DBUS_FUNCTION_NAME, filename); -#ifdef DBUS_WIN_FIXME +#ifdef DBUS_WIN _dbus_verbose("TODO: Fix memory leaks after running check_shell_service_success_auto_start\n"); _dbus_sleep_milliseconds (500); #endif diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 6ca77675..881dfa14 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -234,7 +234,6 @@ // system type defines #if defined(_WIN32) || defined(_WIN64) || defined (_WIN32_WCE) # define DBUS_WIN -# define DBUS_WIN_FIXME 1 # ifdef _WIN32_WCE # define DBUS_WINCE # else diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index c4cbd315..16c20e83 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -254,7 +254,7 @@ dbus_bool_t _dbus_decrement_fail_alloc_counter (void) { _dbus_initialize_malloc_debug (); -#ifdef DBUS_WIN_FIXME +#ifdef DBUS_WIN { static dbus_bool_t called = 0; From 0c0e7361aee9d5a96989c42163f3ddb33d6ab6bc Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 5 Dec 2018 07:56:22 +0100 Subject: [PATCH 3/3] Adds uac manifest to all executable test files to prevent the Windows 740 error when running The case occurred during test-pending-call-dispatch. To avoid further applications being affected in the future, the manifest is added to all test applications. Windows Error 740 is defined as 'The Requested Operation Requires Elevation' --- cmake/modules/Macros.cmake | 34 ++++++++++++++++++++++++++++++++-- cmake/tools/CMakeLists.txt | 8 +------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index 63b2171b..46664ef4 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -31,7 +31,12 @@ if(DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Win endif() macro(add_test_executable _target _source) - add_executable(${_target} ${_source}) + set(_sources "${_source}") + if(WIN32 AND NOT MSVC) + # avoid triggering UAC + add_uac_manifest(_sources) + endif() + add_executable(${_target} ${_sources}) target_link_libraries(${_target} ${ARGN}) if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows") # run tests with binfmt_misc @@ -58,7 +63,12 @@ macro(add_test_executable _target _source) endmacro(add_test_executable) macro(add_helper_executable _target _source) - add_executable(${_target} ${_source}) + set(_sources "${_source}") + if(WIN32 AND NOT MSVC) + # avoid triggering UAC + add_uac_manifest(_sources) + endif() + add_executable(${_target} ${_sources}) target_link_libraries(${_target} ${ARGN}) endmacro(add_helper_executable) @@ -115,3 +125,23 @@ macro(generate_warning_cflags target warnings disabled_warnings error_warnings) message("generate_warning_cflags return: ${${target}}") endif() endmacro() + +# +# Avoid triggering UAC +# +# This macro adds an rc file to _sources that is +# linked to a target and prevents UAC from making +# requests for administrator access. +# +macro(add_uac_manifest _sources) + # 1 is the resource ID, ID_MANIFEST + # 24 is the resource type, RT_MANIFEST + # constants are used because of a bug in windres + # see https://stackoverflow.com/questions/33000158/embed-manifest-file-to-require-administrator-execution-level-with-mingw32 + get_filename_component(UAC_FILE ${CMAKE_SOURCE_DIR}/../tools/Win32.Manifest REALPATH) + set(outfile ${CMAKE_BINARY_DIR}/disable-uac.rc) + if(NOT EXISTS outfile) + file(WRITE ${outfile} "1 24 \"${UAC_FILE}\"\n") + endif() + list(APPEND ${_sources} ${outfile}) +endmacro() diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt index 704e3a49..72fa6727 100644 --- a/cmake/tools/CMakeLists.txt +++ b/cmake/tools/CMakeLists.txt @@ -91,13 +91,7 @@ if(WIN32) list(APPEND dbus_update_activation_environment_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/versioninfo-${DBUS_VER_INTERNAL_NAME}.rc) endif() if(WIN32 AND NOT MSVC) - # avoid dbus-update-activation-environment triggering UAC - # 1 is the resource ID, ID_MANIFEST - # 24 is the resource type, RT_MANIFEST - # constants are used because of a bug in windres - # see https://stackoverflow.com/questions/33000158/embed-manifest-file-to-require-administrator-execution-level-with-mingw32 - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/disable-uac.rc "1 24 \"${CMAKE_SOURCE_DIR}/../tools/Win32.Manifest\"\n") - list(APPEND dbus_update_activation_environment_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/disable-uac.rc) + add_uac_manifest(dbus_update_activation_environment_SOURCES) endif() add_executable(dbus-update-activation-environment ${dbus_update_activation_environment_SOURCES}) target_link_libraries(dbus-update-activation-environment ${DBUS_LIBRARIES})