OSDN Git Service

Fix memory leaks (#596)
authorhlop <thehlopster@gmail.com>
Mon, 1 Feb 2021 23:35:19 +0000 (02:35 +0300)
committerGitHub <noreply@github.com>
Mon, 1 Feb 2021 23:35:19 +0000 (08:35 +0900)
Allocated array should be deallocated with `delete []` Deallocating it with `delete` can cause memory leaks.

Plugins/src_VCPP/RCLocalizationHelper/widestr.h

index 7a067e4..a5d655a 100644 (file)
@@ -48,7 +48,7 @@ public:
                m_wstr = (wchar_t *)new wchar_t[maxlen];
                m_maxlen = maxlen;
                wcscpy(m_wstr, old ? old : L"");
-               if (old) { delete (wchar_t *)old; }
+               if (old) { delete[] (wchar_t *)old; }
        }
        void append(const wchar_t * wstr, int maxlen=-1)
        {
@@ -80,7 +80,7 @@ public:
 private:
        void release()
        {
-               delete m_wstr;
+               delete[] m_wstr;
                m_wstr = 0;
        }
        void update()