From fe444f0217452b1ca008835535d93b59e0e4d334 Mon Sep 17 00:00:00 2001 From: Lionel Debroux Date: Sun, 9 Dec 2007 19:54:14 +0100 Subject: [PATCH] msi: Fix memory leaks (found by Smatch). --- dlls/msi/database.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/dlls/msi/database.c b/dlls/msi/database.c index f4ed1d7ece..a690ee449c 100644 --- a/dlls/msi/database.c +++ b/dlls/msi/database.c @@ -552,7 +552,7 @@ static LPWSTR msi_build_insertsql_columns(LPWSTR *columns_data, LPWSTR *types, D static LPWSTR msi_build_insertsql_data(LPWSTR **records, LPWSTR *types, DWORD num_columns, DWORD irec) { - LPWSTR columns; + LPWSTR columns, temp_columns; DWORD sql_size = 1, i; WCHAR expanded[128]; @@ -578,6 +578,7 @@ static LPWSTR msi_build_insertsql_data(LPWSTR **records, LPWSTR *types, DWORD nu lstrcpyW(expanded, empty); break; default: + HeapFree( GetProcessHeap(), 0, columns ); return NULL; } @@ -585,9 +586,13 @@ static LPWSTR msi_build_insertsql_data(LPWSTR **records, LPWSTR *types, DWORD nu expanded[lstrlenW(expanded) - 2] = '\0'; sql_size += lstrlenW(expanded); - columns = msi_realloc(columns, sql_size * sizeof(WCHAR)); - if (!columns) + temp_columns = msi_realloc(columns, sql_size * sizeof(WCHAR)); + if (!temp_columns) + { + HeapFree( GetProcessHeap(), 0, columns); return NULL; + } + columns = temp_columns; lstrcatW(columns, expanded); } @@ -654,6 +659,7 @@ UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file) LPWSTR *columns, *types, *labels; LPWSTR path, ptr, data; LPWSTR **records; + LPWSTR **temp_records; static const WCHAR backslash[] = {'\\',0}; @@ -680,7 +686,10 @@ UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file) records = msi_alloc(sizeof(LPWSTR *)); if (!records) - return ERROR_OUTOFMEMORY; + { + r = ERROR_OUTOFMEMORY; + goto done; + } /* read in the table records */ while (*ptr) @@ -688,9 +697,13 @@ UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file) msi_parse_line( &ptr, &records[num_records], NULL ); num_records++; - records = msi_realloc(records, (num_records + 1) * sizeof(LPWSTR *)); - if (!records) - return ERROR_OUTOFMEMORY; + temp_records = msi_realloc(records, (num_records + 1) * sizeof(LPWSTR *)); + if (!temp_records) + { + r = ERROR_OUTOFMEMORY; + goto done; + } + records = temp_records; } r = msi_add_table_to_db( db, columns, types, labels, num_labels, num_columns );