aboutsummaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-01-15 14:00:12 +0100
committerPierre Ossman <ossman@cendio.se>2023-02-04 14:03:13 +0100
commit15a393912673e2ae65b9b3a28f9b82f967c49f98 (patch)
treef74735c6a099081bdae872ea5203ee13decba5a8 /win
parent19badc4def7d2bee677da3a02e1117f1e051a8cd (diff)
downloadtigervnc-15a393912673e2ae65b9b3a28f9b82f967c49f98.tar.gz
tigervnc-15a393912673e2ae65b9b3a28f9b82f967c49f98.zip
Free char buffer directly
It's extreme overkill to inherit from CharArray just to get the automatic freeing of the buffer when the object is destroyed.
Diffstat (limited to 'win')
-rw-r--r--win/rfb_win32/Registry.cxx23
-rw-r--r--win/rfb_win32/Registry.h5
-rw-r--r--win/rfb_win32/Win32Util.cxx5
-rw-r--r--win/rfb_win32/Win32Util.h7
4 files changed, 24 insertions, 16 deletions
diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx
index dccaa727..aa497a29 100644
--- a/win/rfb_win32/Registry.cxx
+++ b/win/rfb_win32/Registry.cxx
@@ -48,9 +48,9 @@ using namespace rfb::win32;
static LogWriter vlog("Registry");
-RegKey::RegKey() : key(0), freeKey(false), valueNameBufLen(0) {}
+RegKey::RegKey() : key(0), freeKey(false), valueName(NULL), valueNameBufLen(0) {}
-RegKey::RegKey(const HKEY k) : key(0), freeKey(false), valueNameBufLen(0) {
+RegKey::RegKey(const HKEY k) : key(0), freeKey(false), valueName(NULL), valueNameBufLen(0) {
LONG result = RegOpenKeyEx(k, 0, 0, KEY_ALL_ACCESS, &key);
if (result != ERROR_SUCCESS)
throw rdr::SystemException("RegOpenKeyEx(HKEY)", result);
@@ -58,7 +58,7 @@ RegKey::RegKey(const HKEY k) : key(0), freeKey(false), valueNameBufLen(0) {
freeKey = true;
}
-RegKey::RegKey(const RegKey& k) : key(0), freeKey(false), valueNameBufLen(0) {
+RegKey::RegKey(const RegKey& k) : key(0), freeKey(false), valueName(NULL), valueNameBufLen(0) {
LONG result = RegOpenKeyEx(k.key, 0, 0, KEY_ALL_ACCESS, &key);
if (result != ERROR_SUCCESS)
throw rdr::SystemException("RegOpenKeyEx(RegKey&)", result);
@@ -68,6 +68,7 @@ RegKey::RegKey(const RegKey& k) : key(0), freeKey(false), valueNameBufLen(0) {
RegKey::~RegKey() {
close();
+ delete [] valueName;
}
@@ -272,15 +273,15 @@ const char* RegKey::getValueName(int i) {
throw rdr::SystemException("RegQueryInfoKey", result);
if (valueNameBufLen < maxValueNameLen + 1) {
valueNameBufLen = maxValueNameLen + 1;
- delete [] valueName.buf;
- valueName.buf = new char[valueNameBufLen];
+ delete [] valueName;
+ valueName = new char[valueNameBufLen];
}
DWORD length = valueNameBufLen;
- result = RegEnumValue(key, i, valueName.buf, &length, NULL, 0, 0, 0);
+ result = RegEnumValue(key, i, valueName, &length, NULL, 0, 0, 0);
if (result == ERROR_NO_MORE_ITEMS) return 0;
if (result != ERROR_SUCCESS)
throw rdr::SystemException("RegEnumValue", result);
- return valueName.buf;
+ return valueName;
}
const char* RegKey::getKeyName(int i) {
@@ -290,13 +291,13 @@ const char* RegKey::getKeyName(int i) {
throw rdr::SystemException("RegQueryInfoKey", result);
if (valueNameBufLen < maxValueNameLen + 1) {
valueNameBufLen = maxValueNameLen + 1;
- delete [] valueName.buf;
- valueName.buf = new char[valueNameBufLen];
+ delete [] valueName;
+ valueName = new char[valueNameBufLen];
}
DWORD length = valueNameBufLen;
- result = RegEnumKeyEx(key, i, valueName.buf, &length, NULL, 0, 0, 0);
+ result = RegEnumKeyEx(key, i, valueName, &length, NULL, 0, 0, 0);
if (result == ERROR_NO_MORE_ITEMS) return 0;
if (result != ERROR_SUCCESS)
throw rdr::SystemException("RegEnumKey", result);
- return valueName.buf;
+ return valueName;
}
diff --git a/win/rfb_win32/Registry.h b/win/rfb_win32/Registry.h
index a387472a..b99c95bc 100644
--- a/win/rfb_win32/Registry.h
+++ b/win/rfb_win32/Registry.h
@@ -22,9 +22,10 @@
#ifndef __RFB_WIN32_REGISTRY_H__
#define __RFB_WIN32_REGISTRY_H__
+#include <string>
+
#include <windows.h>
#include <rfb_win32/Security.h>
-#include <rfb/util.h>
namespace rfb {
@@ -101,7 +102,7 @@ namespace rfb {
protected:
HKEY key;
bool freeKey;
- CharArray valueName;
+ char* valueName;
DWORD valueNameBufLen;
};
diff --git a/win/rfb_win32/Win32Util.cxx b/win/rfb_win32/Win32Util.cxx
index ad301574..e806b1db 100644
--- a/win/rfb_win32/Win32Util.cxx
+++ b/win/rfb_win32/Win32Util.cxx
@@ -28,6 +28,7 @@
#include <rfb_win32/Handle.h>
#include <rdr/HexOutStream.h>
#include <rdr/Exception.h>
+#include <rfb/util.h>
#include <stdio.h>
namespace rfb {
@@ -60,6 +61,10 @@ FileVersionInfo::FileVersionInfo(const char* filename) {
throw rdr::SystemException("GetVersionInfo failed", GetLastError());
}
+FileVersionInfo::~FileVersionInfo() {
+ delete [] buf;
+}
+
const char* FileVersionInfo::getVerString(const char* name, DWORD langId) {
uint8_t langIdBuf[sizeof(langId)];
for (int i=sizeof(langIdBuf)-1; i>=0; i--) {
diff --git a/win/rfb_win32/Win32Util.h b/win/rfb_win32/Win32Util.h
index 642e377f..24d5905d 100644
--- a/win/rfb_win32/Win32Util.h
+++ b/win/rfb_win32/Win32Util.h
@@ -25,15 +25,16 @@
#ifndef __RFB_WIN32_GDIUTIL_H__
#define __RFB_WIN32_GDIUTIL_H__
-#include <rfb/util.h>
-
namespace rfb {
namespace win32 {
- struct FileVersionInfo : public CharArray {
+ struct FileVersionInfo {
FileVersionInfo(const char* filename=0);
+ ~FileVersionInfo();
const char* getVerString(const char* name, DWORD langId = 0x080904b0);
+ private:
+ char *buf;
};
// Center the window to a rectangle, or to a parent window.