Skip to content

Commit 6799234

Browse files
committed
fix: Do not alloc console in debug mode
1 parent a6f3751 commit 6799234

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/loader/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ pub fn is_winserver() -> bool {
2525
!unsafe { VerifyVersionInfoA(&mut osvi, VER_PRODUCT_TYPE, cond_mask).is_ok() }
2626
}
2727

28+
#[allow(dead_code)]
2829
fn alloc_console_if_needed() {
2930
unsafe {
3031
if AttachConsole(ATTACH_PARENT_PROCESS).is_err() {
31-
AllocConsole();
32+
AllocConsole().expect("[Error]: Failed to allocate console");
3233
}
3334
}
3435
}
3536

37+
#[allow(dead_code)]
3638
fn free_console_if_needed() {
3739
unsafe {
3840
FreeConsole().ok();
@@ -41,10 +43,9 @@ fn free_console_if_needed() {
4143

4244
pub fn run() {
4345
let args = args::Args::parse();
44-
if args.auto {
45-
unsafe {
46-
FreeConsole().ok();
47-
}
46+
#[cfg(not(debug_assertions))]
47+
if !args.auto {
48+
alloc_console_if_needed();
4849
}
4950
let mut ctx = Ctx::default_with_name(&args.name);
5051
if args.disable {
@@ -120,7 +121,8 @@ pub fn run() {
120121
CoUninitialize();
121122
}
122123

123-
// if !args.auto {
124-
// free_console_if_needed();
125-
// }
124+
#[cfg(not(debug_assertions))]
125+
if !args.auto {
126+
free_console_if_needed();
127+
}
126128
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
1+
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
22

33
use defender_core::loader;
44

0 commit comments

Comments
 (0)