Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
2435f46d
Commit
2435f46d
authored
Feb 09, 2020
by
bandana2004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix registry key handle leak in win_eventlog_sink::add_registry_info
parent
4bece787
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
include/spdlog/sinks/win_eventlog_sink.h
include/spdlog/sinks/win_eventlog_sink.h
+16
-8
No files found.
include/spdlog/sinks/win_eventlog_sink.h
View file @
2435f46d
...
...
@@ -306,13 +306,23 @@ public:
event_id_
=
event_id
;
std
::
string
subkey
=
fmt
::
format
(
"SYSTEM
\\
CurrentControlSet
\\
Services
\\
EventLog
\\
{}
\\
{}"
,
log
,
source_
);
std
::
string
logSourceRegKeyName
=
fmt
::
format
(
"SYSTEM
\\
CurrentControlSet
\\
Services
\\
EventLog
\\
{}
\\
{}"
,
log
,
source_
);
struct
hkey_t
{
::
HKEY
handle_
{};
~
hkey_t
()
{
if
(
handle_
)
RegCloseKey
(
handle_
);
}
}
logSourceRegKey
;
::
HKEY
hkey
{};
DWORD
disposition
{};
long
stat
=
RegCreateKeyEx
(
HKEY_LOCAL_MACHINE
,
subkey
.
c_str
(),
0
,
NULL
,
long
stat
=
RegCreateKeyEx
(
HKEY_LOCAL_MACHINE
,
logSourceRegKeyName
.
c_str
(),
0
,
NULL
,
REG_OPTION_NON_VOLATILE
,
KEY_SET_VALUE
,
NULL
,
&
hkey
,
&
disposition
);
&
logSourceRegKey
.
handle_
,
&
disposition
);
if
(
stat
==
ERROR_SUCCESS
)
{
if
(
disposition
==
REG_CREATED_NEW_KEY
&&
!
message_file_path
.
empty
())
...
...
@@ -324,12 +334,12 @@ public:
std
::
vector
<
char
>
expanded_message_file_path
(
expanded_message_file_path_length
);
ExpandEnvironmentStrings
(
message_file_path
.
c_str
(),
expanded_message_file_path
.
data
(),
expanded_message_file_path_length
);
// this can't fail if the preivous ExpandEnvironmentStrings succeeded
stat
=
RegSetValueEx
(
hkey
,
"EventMessageFile"
,
0
,
REG_SZ
,
(
LPBYTE
)
expanded_message_file_path
.
data
(),
expanded_message_file_path_length
);
stat
=
RegSetValueEx
(
logSourceRegKey
.
handle_
,
"EventMessageFile"
,
0
,
REG_SZ
,
(
LPBYTE
)
expanded_message_file_path
.
data
(),
expanded_message_file_path_length
);
if
(
stat
!=
ERROR_SUCCESS
)
SPDLOG_THROW
(
win32_error
(
"RegSetValueEx"
,
stat
));
DWORD
typesSupported
=
7
;
stat
=
RegSetValueEx
(
hkey
,
"TypesSupported"
,
0
,
REG_DWORD
,
(
LPBYTE
)
&
typesSupported
,
sizeof
(
DWORD
));
stat
=
RegSetValueEx
(
logSourceRegKey
.
handle_
,
"TypesSupported"
,
0
,
REG_DWORD
,
(
LPBYTE
)
&
typesSupported
,
sizeof
(
DWORD
));
if
(
stat
!=
ERROR_SUCCESS
)
SPDLOG_THROW
(
win32_error
(
"RegSetValueEx"
,
stat
));
}
...
...
@@ -338,8 +348,6 @@ public:
{
SPDLOG_THROW
(
win32_error
(
"RegCreateKeyEx"
,
stat
));
}
RegCloseKey
(
hkey
);
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment