Commit 3e231d0f authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

msi: Fix memory leak on realloc failure in create_diff_row_query (cppcheck).

parent a8e2aa6c
......@@ -1412,7 +1412,7 @@ static LPWSTR get_key_value(MSIQUERY *view, LPCWSTR key, MSIRECORD *rec)
static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
LPWSTR table, MSIRECORD *rec)
{
LPWSTR query = NULL, clause = NULL, val;
WCHAR *query = NULL, *clause = NULL, *new_clause, *val;
LPCWSTR setptr, key;
DWORD size, oldsize;
MSIRECORD *keys;
......@@ -1422,10 +1422,6 @@ static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
if (r != ERROR_SUCCESS)
return NULL;
clause = calloc(1, sizeof(WCHAR));
if (!clause)
goto done;
size = 1;
count = MSI_RecordGetFieldCount(keys);
for (i = 1; i <= count; i++)
......@@ -1440,12 +1436,13 @@ static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
oldsize = size;
size += lstrlenW(setptr) + lstrlenW(key) + lstrlenW(val) - 4;
clause = realloc(clause, size * sizeof(WCHAR));
if (!clause)
new_clause = realloc(clause, size * sizeof(WCHAR));
if (!new_clause)
{
free(val);
goto done;
}
clause = new_clause;
swprintf(clause + oldsize - 1, size - (oldsize - 1), setptr, key, val);
free(val);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment