Skip to content

Commit

Permalink
fix potential problems
Browse files Browse the repository at this point in the history
  • Loading branch information
yqs112358 committed Mar 20, 2021
1 parent 845bde9 commit 3e2ed0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 0 additions & 4 deletions CrashLogger.vcxproj.user

This file was deleted.

13 changes: 10 additions & 3 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void log(const char* format, ...)
va_start(args, format);
vprintf(format, args);
fflush(stdout);
if (fLog != NULL)
if (fLog != NULL && fLog != INVALID_HANDLE_VALUE)
{
vfprintf(fLog, format, args);
fflush(fLog);
Expand All @@ -31,6 +31,13 @@ LONG WINAPI CrashLogger(PEXCEPTION_POINTERS pe)
log("[Crashed!]\n");
HANDLE hProcess = GetCurrentProcess();
HANDLE hThread = GetCurrentThread();
CreateDirectory(L"logs", NULL);
errno_t res = fopen_s(&fLog, LOG_OUTPUT_PATH, "w");
if (res != 0)
{
fLog = NULL;
log("[Warning] Fail to open log file! Error Code:%d\n",res);
}

/// <summary>
/// StackWalk
Expand Down Expand Up @@ -93,15 +100,15 @@ BOOL APIENTRY DllMain( HMODULE hModule,
{
case DLL_PROCESS_ATTACH:
SystemHandler = SetUnhandledExceptionFilter(CrashLogger);
fopen_s(&fLog, LOG_OUTPUT_PATH, "w");
printf("[CrashLogger] CrashLogger loaded.\n");
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
fclose(fLog);
if (fLog != NULL && fLog != INVALID_HANDLE_VALUE)
fclose(fLog);
break;
}
return TRUE;
Expand Down

0 comments on commit 3e2ed0c

Please sign in to comment.