From a3bf37fb4f758469b7b68ad7dcca170913fcd912 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 8 Dec 2009 10:03:34 +0000 Subject: Fixed not exception-safe constructor, which could lead to possible memory leak (thanks to Bartek Szurgot). Get rid of const-ness on factories. --- src/net/maildir/format/courierMaildirFormat.cpp | 12 ++++++------ src/net/maildir/format/kmailMaildirFormat.cpp | 12 ++++++------ src/net/maildir/maildirFolder.cpp | 12 ++++++------ src/net/maildir/maildirMessage.cpp | 6 +++--- src/net/maildir/maildirStore.cpp | 2 +- src/platforms/posix/posixHandler.cpp | 20 ++++++++------------ src/platforms/windows/windowsHandler.cpp | 16 ++++++---------- 7 files changed, 36 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/net/maildir/format/courierMaildirFormat.cpp b/src/net/maildir/format/courierMaildirFormat.cpp index 6dbda80b..721517e8 100644 --- a/src/net/maildir/format/courierMaildirFormat.cpp +++ b/src/net/maildir/format/courierMaildirFormat.cpp @@ -49,7 +49,7 @@ const string courierMaildirFormat::getName() const void courierMaildirFormat::createFolder(const folder::path& path) { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); if (!fsf->isValidPath(folderPathToFileSystemPath(path, ROOT_DIRECTORY))) throw exceptions::invalid_folder_name(); @@ -80,7 +80,7 @@ void courierMaildirFormat::createFolder(const folder::path& path) void courierMaildirFormat::destroyFolder(const folder::path& path) { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); // Recursively delete directories of subfolders const std::vector folders = listFolders(path, true); @@ -119,7 +119,7 @@ void courierMaildirFormat::renameFolder void courierMaildirFormat::renameFolderImpl (const folder::path& oldPath, const folder::path& newPath) { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); const utility::file::path oldFSPath = folderPathToFileSystemPath(oldPath, ROOT_DIRECTORY); @@ -134,7 +134,7 @@ void courierMaildirFormat::renameFolderImpl bool courierMaildirFormat::folderExists(const folder::path& path) const { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create (folderPathToFileSystemPath(path, ROOT_DIRECTORY)); @@ -254,7 +254,7 @@ const std::vector courierMaildirFormat::listFolders bool courierMaildirFormat::listDirectories(const folder::path& root, std::vector & dirs, const bool onlyTestForExistence) const { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create (getContext()->getStore()->getFileSystemPath()); @@ -496,7 +496,7 @@ const folder::path::component courierMaildirFormat::fromModifiedUTF7(const strin bool courierMaildirFormat::supports() const { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create (getContext()->getStore()->getFileSystemPath()); diff --git a/src/net/maildir/format/kmailMaildirFormat.cpp b/src/net/maildir/format/kmailMaildirFormat.cpp index 5fb75feb..a21d1061 100644 --- a/src/net/maildir/format/kmailMaildirFormat.cpp +++ b/src/net/maildir/format/kmailMaildirFormat.cpp @@ -49,7 +49,7 @@ const string kmailMaildirFormat::getName() const void kmailMaildirFormat::createFolder(const folder::path& path) { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); if (!fsf->isValidPath(folderPathToFileSystemPath(path, ROOT_DIRECTORY))) throw exceptions::invalid_folder_name(); @@ -75,7 +75,7 @@ void kmailMaildirFormat::createFolder(const folder::path& path) void kmailMaildirFormat::destroyFolder(const folder::path& path) { // Delete 'folder' and '.folder.directory' directories - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); maildirUtils::recursiveFSDelete(fsf->create (folderPathToFileSystemPath(path, ROOT_DIRECTORY))); // root @@ -87,7 +87,7 @@ void kmailMaildirFormat::destroyFolder(const folder::path& path) bool kmailMaildirFormat::folderExists(const folder::path& path) const { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create (folderPathToFileSystemPath(path, ROOT_DIRECTORY)); @@ -177,7 +177,7 @@ const std::vector kmailMaildirFormat::listFolders void kmailMaildirFormat::listFoldersImpl (std::vector & list, const folder::path& root, const bool recursive) const { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create(folderPathToFileSystemPath(root, root.isEmpty() ? ROOT_DIRECTORY : CONTAINER_DIRECTORY)); @@ -226,7 +226,7 @@ bool kmailMaildirFormat::isSubfolderDirectory(const utility::file& file) void kmailMaildirFormat::renameFolder(const folder::path& oldPath, const folder::path& newPath) { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create (folderPathToFileSystemPath(oldPath, ROOT_DIRECTORY)); @@ -277,7 +277,7 @@ void kmailMaildirFormat::renameFolder(const folder::path& oldPath, const folder: bool kmailMaildirFormat::folderHasSubfolders(const folder::path& path) const { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref rootDir = fsf->create (folderPathToFileSystemPath(path, CONTAINER_DIRECTORY)); diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp index 3e361ae1..dd680c9c 100644 --- a/src/net/maildir/maildirFolder.cpp +++ b/src/net/maildir/maildirFolder.cpp @@ -264,7 +264,7 @@ void maildirFolder::scanFolder() m_messageCount = 0; m_unreadMessageCount = 0; - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); utility::file::path newDirPath = store->getFormat()->folderPathToFileSystemPath (m_path, maildirFormat::NEW_DIRECTORY); @@ -760,7 +760,7 @@ void maildirFolder::setMessageFlagsImpl { ref store = m_store.acquire(); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); utility::file::path curDirPath = store->getFormat()-> folderPathToFileSystemPath(m_path, maildirFormat::CUR_DIRECTORY); @@ -832,7 +832,7 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size, else if (m_mode == MODE_READ_ONLY) throw exceptions::illegal_state("Folder is read-only"); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); utility::file::path tmpDirPath = store->getFormat()-> folderPathToFileSystemPath(m_path,maildirFormat::TMP_DIRECTORY); @@ -918,7 +918,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress) { - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); ref file = fsf->create(tmpDirPath / filename); @@ -1058,7 +1058,7 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector { ref store = m_store.acquire(); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); utility::file::path curDirPath = store->getFormat()->folderPathToFileSystemPath (m_path, maildirFormat::CUR_DIRECTORY); @@ -1200,7 +1200,7 @@ void maildirFolder::expunge() else if (m_mode == MODE_READ_ONLY) throw exceptions::illegal_state("Folder is read-only"); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); utility::file::path curDirPath = store->getFormat()-> folderPathToFileSystemPath(m_path, maildirFormat::CUR_DIRECTORY); diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp index ed87cdb3..8999d847 100644 --- a/src/net/maildir/maildirMessage.cpp +++ b/src/net/maildir/maildirMessage.cpp @@ -346,7 +346,7 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progressLis { ref folder = m_folder.acquire(); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); const utility::file::path path = folder->getMessageFSPath(m_num); ref file = fsf->create(path); @@ -393,7 +393,7 @@ void maildirMessage::fetchPartHeader(ref p) ref mp = p.dynamicCast (); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); const utility::file::path path = folder->getMessageFSPath(m_num); ref file = fsf->create(path); @@ -430,7 +430,7 @@ void maildirMessage::fetch(ref msgFolder, const int options) if (folder != msgFolder) throw exceptions::folder_not_found(); - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); const utility::file::path path = folder->getMessageFSPath(m_num); ref file = fsf->create(path); diff --git a/src/net/maildir/maildirStore.cpp b/src/net/maildir/maildirStore.cpp index 3b770246..26f4593a 100644 --- a/src/net/maildir/maildirStore.cpp +++ b/src/net/maildir/maildirStore.cpp @@ -132,7 +132,7 @@ void maildirStore::connect() throw exceptions::already_connected(); // Get root directory - utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory(); + ref fsf = platform::getHandler()->getFileSystemFactory(); m_fsPath = fsf->stringToPath(GET_PROPERTY(string, PROPERTY_SERVER_ROOTPATH)); diff --git a/src/platforms/posix/posixHandler.cpp b/src/platforms/posix/posixHandler.cpp index f43972ee..104bc404 100644 --- a/src/platforms/posix/posixHandler.cpp +++ b/src/platforms/posix/posixHandler.cpp @@ -55,18 +55,14 @@ posixHandler::posixHandler() m_socketFactory = vmime::create (); #endif #if VMIME_HAVE_FILESYSTEM_FEATURES - m_fileSysFactory = new posixFileSystemFactory(); - m_childProcFactory = new posixChildProcessFactory(); + m_fileSysFactory = vmime::create (); + m_childProcFactory = vmime::create (); #endif } posixHandler::~posixHandler() { -#if VMIME_HAVE_FILESYSTEM_FEATURES - delete (m_fileSysFactory); - delete (m_childProcFactory); -#endif } @@ -173,9 +169,9 @@ unsigned int posixHandler::getProcessId() const #if VMIME_HAVE_MESSAGING_FEATURES -ref posixHandler::getSocketFactory() const +ref posixHandler::getSocketFactory() { - return m_socketFactory.dynamicCast (); + return m_socketFactory; } #endif @@ -183,15 +179,15 @@ ref posixHandler::getSocketFactory() const #if VMIME_HAVE_FILESYSTEM_FEATURES -vmime::utility::fileSystemFactory* posixHandler::getFileSystemFactory() const +ref posixHandler::getFileSystemFactory() { - return (m_fileSysFactory); + return m_fileSysFactory; } -vmime::utility::childProcessFactory* posixHandler::getChildProcessFactory() const +ref posixHandler::getChildProcessFactory() { - return (m_childProcFactory); + return m_childProcFactory; } #endif diff --git a/src/platforms/windows/windowsHandler.cpp b/src/platforms/windows/windowsHandler.cpp index 404d3cbc..1a37c839 100644 --- a/src/platforms/windows/windowsHandler.cpp +++ b/src/platforms/windows/windowsHandler.cpp @@ -49,17 +49,13 @@ windowsHandler::windowsHandler() m_socketFactory = vmime::create (); #endif #if VMIME_HAVE_FILESYSTEM_FEATURES - m_fileSysFactory = new windowsFileSystemFactory(); + m_fileSysFactory = vmime::create (); #endif } windowsHandler::~windowsHandler() { -#if VMIME_HAVE_FILESYSTEM_FEATURES - delete (m_fileSysFactory); -#endif - WSACleanup(); } @@ -240,9 +236,9 @@ unsigned int windowsHandler::getProcessId() const #if VMIME_HAVE_MESSAGING_FEATURES -ref windowsHandler::getSocketFactory() const +ref windowsHandler::getSocketFactory() { - return m_socketFactory.dynamicCast (); + return m_socketFactory; } #endif @@ -250,13 +246,13 @@ ref windowsHandler::getSocketFactory() const #if VMIME_HAVE_FILESYSTEM_FEATURES -vmime::utility::fileSystemFactory* windowsHandler::getFileSystemFactory() const +ref windowsHandler::getFileSystemFactory() { - return (m_fileSysFactory); + return m_fileSysFactory; } -vmime::utility::childProcessFactory* windowsHandler::getChildProcessFactory() const +ref windowsHandler::getChildProcessFactory() { // TODO: Not implemented return (NULL); -- cgit v1.2.3