Merge pull request #10454 from akallabeth/leak_fix

Leak fixes
This commit is contained in:
akallabeth 2024-08-08 10:45:30 +02:00 committed by GitHub
commit 9c24bff031
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 30 deletions

View File

@ -1387,14 +1387,10 @@ BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs)
{
char buffer[2048] = { 0 };
char dbuffer[2048] = { 0 };
WCHAR* clientName = NULL;
size_t clientNameLength = 0;
BYTE connectionType = 0;
HIGH_COLOR_DEPTH highColorDepth = HIGH_COLOR_4BPP;
UINT16 earlyCapabilityFlags = 0;
WCHAR* clientDigProductId = NULL;
size_t clientDigProductIdLength = 0;
const rdpSettings* settings = mcs_get_const_settings(mcs);
WINPR_ASSERT(s);
@ -1406,9 +1402,6 @@ BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs)
if (!gcc_write_user_data_header(s, CS_CORE, 234))
return FALSE;
clientName = ConvertUtf8ToWCharAlloc(settings->ClientHostname, &clientNameLength);
clientDigProductId =
ConvertUtf8ToWCharAlloc(settings->ClientProductId, &clientDigProductIdLength);
Stream_Write_UINT32(s, settings->RdpVersion); /* Version */
Stream_Write_UINT16(s, settings->DesktopWidth); /* DesktopWidth */
@ -1419,15 +1412,17 @@ BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs)
Stream_Write_UINT32(s, settings->KeyboardLayout); /* KeyboardLayout */
Stream_Write_UINT32(s, settings->ClientBuild); /* ClientBuild */
/* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
if (!Stream_EnsureRemainingCapacity(s, 32 + 12 + 64 + 8))
return FALSE;
/* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
size_t clientNameLength = 0;
WCHAR* clientName = ConvertUtf8ToWCharAlloc(settings->ClientHostname, &clientNameLength);
if (clientNameLength >= 16)
{
clientNameLength = 16;
clientName[clientNameLength - 1] = 0;
}
if (!Stream_EnsureRemainingCapacity(s, 32 + 12 + 64 + 8))
return FALSE;
Stream_Write(s, clientName, (clientNameLength * 2));
Stream_Zero(s, 32 - (clientNameLength * 2));
@ -1455,15 +1450,19 @@ BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs)
Stream_Write_UINT16(s, SupportedColorDepths); /* supportedColorDepths */
Stream_Write_UINT16(s, earlyCapabilityFlags); /* earlyCapabilityFlags */
if (!Stream_EnsureRemainingCapacity(s, 64 + 24))
return FALSE;
/* clientDigProductId (64 bytes, null-terminated unicode, truncated to 31 characters) */
size_t clientDigProductIdLength = 0;
WCHAR* clientDigProductId =
ConvertUtf8ToWCharAlloc(settings->ClientProductId, &clientDigProductIdLength);
if (clientDigProductIdLength >= 32)
{
clientDigProductIdLength = 32;
clientDigProductId[clientDigProductIdLength - 1] = 0;
}
if (!Stream_EnsureRemainingCapacity(s, 64 + 24))
return FALSE;
Stream_Write(s, clientDigProductId, (clientDigProductIdLength * 2));
Stream_Zero(s, 64 - (clientDigProductIdLength * 2));
free(clientDigProductId);

View File

@ -30,6 +30,7 @@
int main(int argc, char** argv)
{
int rc = 1;
GC gc = NULL;
int depth = 0;
int x = 0;
@ -100,12 +101,12 @@ int main(int argc, char** argv)
engine = rdtk_engine_new();
if (!engine)
return 1;
goto fail;
scanline = width * 4;
buffer = (uint8_t*)calloc(height, scanline);
if (!buffer)
return 1;
goto fail;
surface = rdtk_surface_new(engine, buffer, width, height, scanline);
@ -146,7 +147,10 @@ int main(int argc, char** argv)
XFlush(display);
XDestroyImage(image);
rc = 0;
fail:
if (image)
XDestroyImage(image);
XCloseDisplay(display);
rdtk_surface_free(surface);
@ -154,5 +158,5 @@ int main(int argc, char** argv)
rdtk_engine_free(engine);
return 0;
return rc;
}

View File

@ -258,7 +258,7 @@ extern "C"
*
* The function does string conversions of any '\0' terminated input string
*
* Supplying len = 0 will return the required size of the buffer in characters.
* Supplying wlen = 0 will return the required size of the buffer in characters.
*
* \warning Supplying a buffer length smaller than required will result in
* platform dependent (=undefined) behaviour!
@ -276,7 +276,7 @@ extern "C"
* The function does string conversions of any input string of len (or less)
* characters until it reaches the first '\0'.
*
* Supplying len = 0 will return the required size of the buffer in characters.
* Supplying wlen = 0 will return the required size of the buffer in characters.
*
* \warning Supplying a buffer length smaller than required will result in
* platform dependent (=undefined) behaviour!
@ -295,7 +295,7 @@ extern "C"
* The function does string conversions of any input string of len characters.
* Any character in the buffer (incuding any '\0') is converted.
*
* Supplying len = 0 will return the required size of the buffer in characters.
* Supplying wlen = 0 will return the required size of the buffer in characters.
*
* \warning Supplying a buffer length smaller than required will result in
* platform dependent (=undefined) behaviour!

View File

@ -385,11 +385,13 @@ LONG RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWOR
case REG_DWORD_BIG_ENDIAN:
case REG_QWORD:
case REG_DWORD:
return reg_read_int(pValue, lpData, lpcbData);
status = reg_read_int(pValue, lpData, lpcbData);
goto end;
case REG_SZ:
{
const size_t length = strnlen(pValue->data.string, UINT32_MAX) * sizeof(WCHAR);
status = ERROR_SUCCESS;
if (lpData != NULL)
{
DWORD size = 0;
@ -404,14 +406,13 @@ LONG RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWOR
size = *lpcbData;
*lpcbData = (DWORD)length;
if (size < length)
return ERROR_MORE_DATA;
status = ERROR_MORE_DATA;
if (ConvertUtf8NToWChar(pValue->data.string, length, cnv.wc, length) < 0)
return ERROR_OUTOFMEMORY;
status = ERROR_OUTOFMEMORY;
}
else if (lpcbData)
*lpcbData = (UINT32)length;
status = ERROR_SUCCESS;
goto end;
}
default:

View File

@ -414,7 +414,7 @@ static SECURITY_STATUS SEC_ENTRY kerberos_AcquireCredentialsHandleW(
void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential,
PTimeStamp ptsExpiry)
{
SECURITY_STATUS status = 0;
SECURITY_STATUS status = SEC_E_INSUFFICIENT_MEMORY;
char* principal = NULL;
char* package = NULL;
@ -422,23 +422,22 @@ static SECURITY_STATUS SEC_ENTRY kerberos_AcquireCredentialsHandleW(
{
principal = ConvertWCharToUtf8Alloc(pszPrincipal, NULL);
if (!principal)
return SEC_E_INSUFFICIENT_MEMORY;
goto fail;
}
if (pszPackage)
{
package = ConvertWCharToUtf8Alloc(pszPackage, NULL);
if (!package)
return SEC_E_INSUFFICIENT_MEMORY;
goto fail;
}
status =
kerberos_AcquireCredentialsHandleA(principal, package, fCredentialUse, pvLogonID, pAuthData,
pGetKeyFn, pvGetKeyArgument, phCredential, ptsExpiry);
if (principal)
free(principal);
if (package)
free(package);
fail:
free(principal);
free(package);
return status;
}