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) ...@@ -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, static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
LPWSTR table, MSIRECORD *rec) LPWSTR table, MSIRECORD *rec)
{ {
LPWSTR query = NULL, clause = NULL, val; WCHAR *query = NULL, *clause = NULL, *new_clause, *val;
LPCWSTR setptr, key; LPCWSTR setptr, key;
DWORD size, oldsize; DWORD size, oldsize;
MSIRECORD *keys; MSIRECORD *keys;
...@@ -1422,10 +1422,6 @@ static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view, ...@@ -1422,10 +1422,6 @@ static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
return NULL; return NULL;
clause = calloc(1, sizeof(WCHAR));
if (!clause)
goto done;
size = 1; size = 1;
count = MSI_RecordGetFieldCount(keys); count = MSI_RecordGetFieldCount(keys);
for (i = 1; i <= count; i++) for (i = 1; i <= count; i++)
...@@ -1440,12 +1436,13 @@ static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view, ...@@ -1440,12 +1436,13 @@ static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
oldsize = size; oldsize = size;
size += lstrlenW(setptr) + lstrlenW(key) + lstrlenW(val) - 4; size += lstrlenW(setptr) + lstrlenW(key) + lstrlenW(val) - 4;
clause = realloc(clause, size * sizeof(WCHAR)); new_clause = realloc(clause, size * sizeof(WCHAR));
if (!clause) if (!new_clause)
{ {
free(val); free(val);
goto done; goto done;
} }
clause = new_clause;
swprintf(clause + oldsize - 1, size - (oldsize - 1), setptr, key, val); swprintf(clause + oldsize - 1, size - (oldsize - 1), setptr, key, val);
free(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