From d699266393d29227d249204faf5036fc0bd6d6ac Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Sun, 13 Dec 2015 09:27:00 +0100 Subject: cppcheck: fix memleak in win32/wintools/msidb/msidb.c Change-Id: I60ce0dbb26a75b49a50a982214d7adfb7ab833a0 Reviewed-on: https://gerrit.libreoffice.org/20679 Tested-by: Jenkins Reviewed-by: Julien Nabet --- setup_native/source/win32/wintools/msidb/msidb.c | 76 +++++++++++++++++++++--- 1 file changed, 67 insertions(+), 9 deletions(-) (limited to 'setup_native') diff --git a/setup_native/source/win32/wintools/msidb/msidb.c b/setup_native/source/win32/wintools/msidb/msidb.c index b4242e1fb27a..733fe58b1205 100644 --- a/setup_native/source/win32/wintools/msidb/msidb.c +++ b/setup_native/source/win32/wintools/msidb/msidb.c @@ -119,24 +119,51 @@ static BOOL msidbExportStorage(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR storageName) sprintf(queryBuffer, "SELECT * FROM _Storages WHERE Name = '%s'", storageNameA); 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); MsiViewExecute(view, 0); 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) { + free(storageNameA); + free(wdirA); return FALSE; } - if ((dataBuffer = malloc(dataLen)) == NULL) return FALSE; - if (MsiRecordReadStream(rec, 2, dataBuffer, &dataLen) != ERROR_SUCCESS) return FALSE; + if ((dataBuffer = malloc(dataLen)) == NULL) + { + 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; storagePath = malloc(len * sizeof(WCHAR)); - if (storagePath == NULL) return FALSE; + if (storagePath == NULL) + { + free(storageNameA); + free(wdirA); + return FALSE; + } strcpy(storagePath, wdirA); strcat(storagePath, "/"); @@ -232,24 +259,52 @@ static BOOL msidbExportStream(LPCWSTR dbfile, LPCWSTR wdir, LPCWSTR streamName) DWORD dataLen = 0; 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); MsiDatabaseOpenView(dbhandle, queryBuffer, &streamListView); MsiViewExecute(streamListView, 0); 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) + { + free(wdirA); + free(streamNameA); return FALSE; + } dataBuffer = malloc(dataLen); - if (!dataBuffer) return FALSE; + if (!dataBuffer) + { + free(wdirA); + free(streamNameA); + return FALSE; + } if (MsiRecordReadStream(rec, 2, dataBuffer, &dataLen) != ERROR_SUCCESS) + { + free(wdirA); + free(streamNameA); return FALSE; + } len = strlen(streamNameA) + 5; streamFileA = malloc(len); - if (streamFileA == NULL) return FALSE; + if (streamFileA == NULL) + { + free(wdirA); + free(streamNameA); + return FALSE; + } strcpy(streamFileA, streamNameA); strcat(streamFileA, ext); @@ -333,7 +388,10 @@ static BOOL msidbImportTables(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR tables[], BOO } } else + { + free(dirNameA); return FALSE; + } closedir(dir); free(dirNameA); } -- cgit v1.2.3