Kaydet (Commit) d6992663 authored tarafından Julien Nabet's avatar Julien Nabet

cppcheck: fix memleak in win32/wintools/msidb/msidb.c

Change-Id: I60ce0dbb26a75b49a50a982214d7adfb7ab833a0
Reviewed-on: https://gerrit.libreoffice.org/20679Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJulien Nabet <serval2412@yahoo.fr>
üst fd5708bf
...@@ -119,24 +119,51 @@ static BOOL msidbExportStorage(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR storageName) ...@@ -119,24 +119,51 @@ static BOOL msidbExportStorage(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR storageName)
sprintf(queryBuffer, "SELECT * FROM _Storages WHERE Name = '%s'", storageNameA); sprintf(queryBuffer, "SELECT * FROM _Storages WHERE Name = '%s'", storageNameA);
r = MsiOpenDatabaseW(dbfile, (LPWSTR) MSIDBOPEN_READONLY, &dbhandle); r = MsiOpenDatabaseW(dbfile, (LPWSTR) MSIDBOPEN_READONLY, &dbhandle);
if (r != ERROR_SUCCESS) return FALSE; if (r != ERROR_SUCCESS)
{
free(storageNameA);
free(wdirA);
return FALSE;
}
MsiDatabaseOpenView(dbhandle, queryBuffer, &view); MsiDatabaseOpenView(dbhandle, queryBuffer, &view);
MsiViewExecute(view, 0); MsiViewExecute(view, 0);
r = MsiViewFetch(view, &rec); r = MsiViewFetch(view, &rec);
if (r != ERROR_SUCCESS) return FALSE; if (r != ERROR_SUCCESS)
{
free(storageNameA);
free(wdirA);
return FALSE;
}
if (MsiRecordReadStream(rec, 2, 0, &dataLen) != ERROR_SUCCESS) if (MsiRecordReadStream(rec, 2, 0, &dataLen) != ERROR_SUCCESS)
{ {
free(storageNameA);
free(wdirA);
return FALSE; return FALSE;
} }
if ((dataBuffer = malloc(dataLen)) == NULL) return FALSE; if ((dataBuffer = malloc(dataLen)) == NULL)
if (MsiRecordReadStream(rec, 2, dataBuffer, &dataLen) != ERROR_SUCCESS) return FALSE; {
free(storageNameA);
free(wdirA);
return FALSE;
}
if (MsiRecordReadStream(rec, 2, dataBuffer, &dataLen) != ERROR_SUCCESS)
{
free(storageNameA);
free(wdirA);
return FALSE;
}
len = strlen(wdirA) + strlen(storageNameA) + 2; len = strlen(wdirA) + strlen(storageNameA) + 2;
storagePath = malloc(len * sizeof(WCHAR)); storagePath = malloc(len * sizeof(WCHAR));
if (storagePath == NULL) return FALSE; if (storagePath == NULL)
{
free(storageNameA);
free(wdirA);
return FALSE;
}
strcpy(storagePath, wdirA); strcpy(storagePath, wdirA);
strcat(storagePath, "/"); strcat(storagePath, "/");
...@@ -232,24 +259,52 @@ static BOOL msidbExportStream(LPCWSTR dbfile, LPCWSTR wdir, LPCWSTR streamName) ...@@ -232,24 +259,52 @@ static BOOL msidbExportStream(LPCWSTR dbfile, LPCWSTR wdir, LPCWSTR streamName)
DWORD dataLen = 0; DWORD dataLen = 0;
r = MsiOpenDatabaseW(dbfile, (LPCWSTR) MSIDBOPEN_READONLY, &dbhandle); r = MsiOpenDatabaseW(dbfile, (LPCWSTR) MSIDBOPEN_READONLY, &dbhandle);
if (r != ERROR_SUCCESS) return FALSE; if (r != ERROR_SUCCESS)
{
free(wdirA);
free(streamNameA);
return FALSE;
}
sprintf(queryBuffer, "SELECT * FROM _Streams WHERE Name = '%s'", streamNameA); sprintf(queryBuffer, "SELECT * FROM _Streams WHERE Name = '%s'", streamNameA);
MsiDatabaseOpenView(dbhandle, queryBuffer, &streamListView); MsiDatabaseOpenView(dbhandle, queryBuffer, &streamListView);
MsiViewExecute(streamListView, 0); MsiViewExecute(streamListView, 0);
r = MsiViewFetch(streamListView, &rec); r = MsiViewFetch(streamListView, &rec);
if (r != ERROR_SUCCESS) return FALSE; if (r != ERROR_SUCCESS)
{
free(wdirA);
free(streamNameA);
return FALSE;
}
if (MsiRecordReadStream(rec, 2, 0, &dataLen) != ERROR_SUCCESS) if (MsiRecordReadStream(rec, 2, 0, &dataLen) != ERROR_SUCCESS)
{
free(wdirA);
free(streamNameA);
return FALSE; return FALSE;
}
dataBuffer = malloc(dataLen); dataBuffer = malloc(dataLen);
if (!dataBuffer) return FALSE; if (!dataBuffer)
{
free(wdirA);
free(streamNameA);
return FALSE;
}
if (MsiRecordReadStream(rec, 2, dataBuffer, &dataLen) != ERROR_SUCCESS) if (MsiRecordReadStream(rec, 2, dataBuffer, &dataLen) != ERROR_SUCCESS)
{
free(wdirA);
free(streamNameA);
return FALSE; return FALSE;
}
len = strlen(streamNameA) + 5; len = strlen(streamNameA) + 5;
streamFileA = malloc(len); streamFileA = malloc(len);
if (streamFileA == NULL) return FALSE; if (streamFileA == NULL)
{
free(wdirA);
free(streamNameA);
return FALSE;
}
strcpy(streamFileA, streamNameA); strcpy(streamFileA, streamNameA);
strcat(streamFileA, ext); strcat(streamFileA, ext);
...@@ -333,7 +388,10 @@ static BOOL msidbImportTables(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR tables[], BOO ...@@ -333,7 +388,10 @@ static BOOL msidbImportTables(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR tables[], BOO
} }
} }
else else
{
free(dirNameA);
return FALSE; return FALSE;
}
closedir(dir); closedir(dir);
free(dirNameA); free(dirNameA);
} }
......
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