[Spice-devel] [vdagent-win PATCH] Remove small memory leak in log_version
Frediano Ziglio
fziglio at redhat.com
Fri Jul 21 13:01:12 UTC 2017
The outer info_buf pointer were always NULL (the internal one
is another variable).
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
OT: wonder why not using FindResource/LoadResource and so on instead
of having to use the module file.
---
common/vdlog.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/common/vdlog.cpp b/common/vdlog.cpp
index 76f4297..c983127 100644
--- a/common/vdlog.cpp
+++ b/common/vdlog.cpp
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <share.h>
+#include <vector>
#define LOG_ROLL_SIZE (1024 * 1024)
@@ -80,7 +81,6 @@ void log_version()
{
DWORD handle;
TCHAR module_fname[MAX_PATH];
- TCHAR* info_buf = NULL;
try {
if (!GetModuleFileName(NULL, module_fname, MAX_PATH)) {
@@ -90,13 +90,13 @@ void log_version()
if (version_inf_size == 0) {
throw;
}
- TCHAR* info_buf = new TCHAR[version_inf_size];
- if (!GetFileVersionInfo(module_fname, handle, version_inf_size, info_buf)) {
+ std::vector<TCHAR> info_buf(version_inf_size);
+ if (!GetFileVersionInfo(module_fname, handle, version_inf_size, &info_buf[0])) {
throw;
}
UINT size;
VS_FIXEDFILEINFO* file_info;
- if (!VerQueryValue(info_buf, L"\\", (VOID**)&file_info, &size) ||
+ if (!VerQueryValue(&info_buf[0], L"\\", (VOID**)&file_info, &size) ||
size < sizeof(VS_FIXEDFILEINFO)) {
throw;
}
@@ -108,5 +108,4 @@ void log_version()
} catch (...) {
vd_printf("get version info failed");
}
- delete[] info_buf;
}
--
2.13.3
More information about the Spice-devel
mailing list