Hans Leidekker : msi: Don' t keep handles open to the patch database in MSI_ApplyPatchW.
Alexandre Julliard
julliard at winehq.org
Mon May 31 11:21:39 CDT 2010
Module: wine
Branch: master
Commit: 8bfc08771c854106f8acf6e5dda8ec1a9727ba7e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=8bfc08771c854106f8acf6e5dda8ec1a9727ba7e
Author: Hans Leidekker <hans at codeweavers.com>
Date: Mon May 31 12:11:34 2010 +0200
msi: Don't keep handles open to the patch database in MSI_ApplyPatchW.
---
dlls/msi/msi.c | 90 +++++++++++++++++++++++++++++++------------------------
1 files changed, 51 insertions(+), 39 deletions(-)
diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c
index 9d8a88a..def6a00 100644
--- a/dlls/msi/msi.c
+++ b/dlls/msi/msi.c
@@ -299,13 +299,56 @@ done:
return r;
}
+static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR **product_codes )
+{
+ MSIHANDLE patch, info = 0;
+ UINT r, type;
+ DWORD size;
+ static WCHAR empty[] = {0};
+ WCHAR *codes;
+
+ r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
+ if (r != ERROR_SUCCESS)
+ return r;
+
+ r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
+ if (r != ERROR_SUCCESS)
+ goto done;
+
+ size = 0;
+ r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
+ if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
+ {
+ ERR("Failed to read product codes from patch\n");
+ r = ERROR_FUNCTION_FAILED;
+ goto done;
+ }
+
+ codes = msi_alloc( ++size * sizeof(WCHAR) );
+ if (!codes)
+ {
+ r = ERROR_OUTOFMEMORY;
+ goto done;
+ }
+
+ r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
+ if (r != ERROR_SUCCESS)
+ msi_free( codes );
+ else
+ *product_codes = codes;
+
+done:
+ MsiCloseHandle( info );
+ MsiCloseHandle( patch );
+ return r;
+}
+
static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
{
- MSIHANDLE patch = 0, info = 0;
- UINT r = ERROR_SUCCESS, type;
- DWORD size = 0;
+ UINT r;
+ DWORD size;
LPCWSTR cmd_ptr = szCommandLine;
- LPWSTR beg, end, cmd = NULL, codes = NULL;
+ LPWSTR beg, end, cmd, codes = NULL;
BOOL succeeded = FALSE;
static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
@@ -314,34 +357,8 @@ static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWS
if (!szPatchPackage || !szPatchPackage[0])
return ERROR_INVALID_PARAMETER;
- if (!szProductCode)
- {
- r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
- if (r != ERROR_SUCCESS)
- return r;
-
- r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
- if (r != ERROR_SUCCESS)
- goto done;
-
- r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
- if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
- {
- ERR("Failed to read product codes from patch\n");
- goto done;
- }
-
- codes = msi_alloc(++size * sizeof(WCHAR));
- if (!codes)
- {
- r = ERROR_OUTOFMEMORY;
- goto done;
- }
-
- r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
- if (r != ERROR_SUCCESS)
- goto done;
- }
+ if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
+ return r;
if (!szCommandLine)
cmd_ptr = empty;
@@ -350,8 +367,8 @@ static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWS
cmd = msi_alloc(size * sizeof(WCHAR));
if (!cmd)
{
- r = ERROR_OUTOFMEMORY;
- goto done;
+ msi_free(codes);
+ return ERROR_OUTOFMEMORY;
}
lstrcpyW(cmd, cmd_ptr);
@@ -380,13 +397,8 @@ static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWS
r = ERROR_SUCCESS;
}
-done:
msi_free(cmd);
msi_free(codes);
-
- MsiCloseHandle(info);
- MsiCloseHandle(patch);
-
return r;
}
More information about the wine-cvs
mailing list