From 8da0e73634efb592f78eccb37bea02230c9de6c2 Mon Sep 17 00:00:00 2001 From: Junjie Huang Date: Tue, 13 Sep 2022 18:25:33 +0800 Subject: [PATCH] fix(windows): fix dangling pointers (#14) * fix(windows): fix dangling pointers a fix to some dangling problem same as https://github.com/tauri-apps/tauri-plugin-single-instance/pull/6 * doc(change): add a change md --- .changes/fix-win-dangling.md | 5 +++++ src/platform_impl/windows.rs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-win-dangling.md diff --git a/.changes/fix-win-dangling.md b/.changes/fix-win-dangling.md new file mode 100644 index 00000000..12c20398 --- /dev/null +++ b/.changes/fix-win-dangling.md @@ -0,0 +1,5 @@ +--- +"tauri-plugin-single-instance": patch +--- + +fix dangling pointers caused by passing `encode_wide().as_ptr()` directly to FFI on Windows. \ No newline at end of file diff --git a/src/platform_impl/windows.rs b/src/platform_impl/windows.rs index 3abec84c..3c92695e 100644 --- a/src/platform_impl/windows.rs +++ b/src/platform_impl/windows.rs @@ -33,12 +33,13 @@ pub fn init(f: Box>) -> TauriPlugin { let class_name = encode_wide(format!("{}-sic", id)); let window_name = encode_wide(format!("{}-siw", id)); + let mutex_name = encode_wide(format!("{}-sim", id)); let hmutex = unsafe { CreateMutexW( std::ptr::null(), true.into(), - encode_wide(format!("{}-sim", id)).as_ptr(), + mutex_name.as_ptr(), ) };