From 2e18a9ea9988ee14b06666d53062e4935e1487f5 Mon Sep 17 00:00:00 2001 From: Raghunath M <84957265+datacore-rm@users.noreply.github.com> Date: Thu, 25 Aug 2022 04:26:40 +0530 Subject: [PATCH] fix mem leak in registry notify change handler (#126) --- module/os/windows/zfs/sysctl_os.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/module/os/windows/zfs/sysctl_os.c b/module/os/windows/zfs/sysctl_os.c index f9182ed0d7f8..ff5792399a0c 100644 --- a/module/os/windows/zfs/sysctl_os.c +++ b/module/os/windows/zfs/sysctl_os.c @@ -338,12 +338,16 @@ sysctl_os_registry_change(PVOID Parameter) if (registry_notify_fd == 0) { registry_notify_fd = sysctl_os_open_registry(RegistryPath); - RtlDuplicateUnicodeString( - RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING | RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, - RegistryPath, - &sysctl_os_RegistryPath); - ExInitializeWorkItem(&wqi, sysctl_os_registry_change, &sysctl_os_RegistryPath); + if (registry_notify_fd != 0) { + RtlDuplicateUnicodeString( + RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING | + RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, + RegistryPath, + &sysctl_os_RegistryPath); + ExInitializeWorkItem(&wqi, sysctl_os_registry_change, + &sysctl_os_RegistryPath); + } } else { // Notified, re-scan registry sysctl_os_init(RegistryPath); @@ -391,9 +395,10 @@ sysctl_os_fini(void) { HANDLE fd = registry_notify_fd; registry_notify_fd = 0; + RtlFreeUnicodeString(&sysctl_os_RegistryPath); + if (fd != 0) ZwClose(fd); - RtlFreeUnicodeString(&sysctl_os_RegistryPath); } int