Skip to content

Commit

Permalink
COMMON: Use ScopedArray in getWindowsVariable()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 29, 2016
1 parent a31a737 commit 2c20f1f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/common/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "src/common/platform.h"
#include "src/common/error.h"
#include "src/common/scopedptr.h"
#include "src/common/encoding.h"
#include "src/common/filepath.h"

Expand Down Expand Up @@ -162,19 +163,14 @@ static inline UString getWindowsVariable(const wchar_t *variable) {
if (!length)
return "";

size_t size = length * sizeof(wchar_t);
byte *data = new byte[size];
const size_t size = length * sizeof(wchar_t);
ScopedArray<byte> data(new byte[size]);

DWORD newLength = GetEnvironmentVariableW(variable, reinterpret_cast<wchar_t *>(data), length);
if (!newLength || (newLength > length)) {
delete[] data;
DWORD newLength = GetEnvironmentVariableW(variable, reinterpret_cast<wchar_t *>(data.get()), length);
if (!newLength || (newLength > length))
return "";
}

UString value = readString(data, size, kEncodingUTF16LE);
delete[] data;

return value;
return readString(data.get(), size, kEncodingUTF16LE);
}

#endif
Expand Down

0 comments on commit 2c20f1f

Please sign in to comment.