Fixed not exception-safe constructor, which could lead to possible memory leak (thanks to Bartek Szurgot). Get rid of const-ness on factories.

This commit is contained in:
Vincent Richard 2009-12-08 10:03:34 +00:00
parent 6016fd5879
commit a3bf37fb4f
14 changed files with 55 additions and 62 deletions

View File

@ -19,6 +19,7 @@ VMIME CONTRIBUTORS
- Georg Sauthoff <gsauthof@techfak.uni-bielefeld.de>
- Pierre Thierry <nowhere.man@levallois.eu.org> (patches for STL algorithms)
- Zarafa <http://developer.zarafa.com/VmimePatches>
- Bartek Szurgot <vempirelord@wp.pl, http://baszerr.org>
Please apologize if I have forgotten someone here. ;)
See SVN Changelog for full list.

View File

@ -49,7 +49,7 @@ const string courierMaildirFormat::getName() const
void courierMaildirFormat::createFolder(const folder::path& path)
{
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
// Recursively delete directories of subfolders
const std::vector <folder::path> 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 <utility::fileSystemFactory> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> rootDir = fsf->create
(folderPathToFileSystemPath(path, ROOT_DIRECTORY));
@ -254,7 +254,7 @@ const std::vector <folder::path> courierMaildirFormat::listFolders
bool courierMaildirFormat::listDirectories(const folder::path& root,
std::vector <string>& dirs, const bool onlyTestForExistence) const
{
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> rootDir = fsf->create
(getContext()->getStore()->getFileSystemPath());

View File

@ -49,7 +49,7 @@ const string kmailMaildirFormat::getName() const
void kmailMaildirFormat::createFolder(const folder::path& path)
{
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> 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 <utility::fileSystemFactory> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> rootDir = fsf->create
(folderPathToFileSystemPath(path, ROOT_DIRECTORY));
@ -177,7 +177,7 @@ const std::vector <folder::path> kmailMaildirFormat::listFolders
void kmailMaildirFormat::listFoldersImpl
(std::vector <folder::path>& list, const folder::path& root, const bool recursive) const
{
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> rootDir = fsf->create
(folderPathToFileSystemPath(path, CONTAINER_DIRECTORY));

View File

@ -264,7 +264,7 @@ void maildirFolder::scanFolder()
m_messageCount = 0;
m_unreadMessageCount = 0;
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
utility::file::path newDirPath = store->getFormat()->folderPathToFileSystemPath
(m_path, maildirFormat::NEW_DIRECTORY);
@ -760,7 +760,7 @@ void maildirFolder::setMessageFlagsImpl
{
ref <maildirStore> store = m_store.acquire();
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> 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 <utility::fileSystemFactory> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::file> file = fsf->create(tmpDirPath / filename);
@ -1058,7 +1058,7 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
{
ref <maildirStore> store = m_store.acquire();
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> 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 <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
utility::file::path curDirPath = store->getFormat()->
folderPathToFileSystemPath(m_path, maildirFormat::CUR_DIRECTORY);

View File

@ -346,7 +346,7 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progressLis
{
ref <const maildirFolder> folder = m_folder.acquire();
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
const utility::file::path path = folder->getMessageFSPath(m_num);
ref <utility::file> file = fsf->create(path);
@ -393,7 +393,7 @@ void maildirMessage::fetchPartHeader(ref <part> p)
ref <maildirPart> mp = p.dynamicCast <maildirPart>();
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
const utility::file::path path = folder->getMessageFSPath(m_num);
ref <utility::file> file = fsf->create(path);
@ -430,7 +430,7 @@ void maildirMessage::fetch(ref <maildirFolder> msgFolder, const int options)
if (folder != msgFolder)
throw exceptions::folder_not_found();
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
const utility::file::path path = folder->getMessageFSPath(m_num);
ref <utility::file> file = fsf->create(path);

View File

@ -132,7 +132,7 @@ void maildirStore::connect()
throw exceptions::already_connected();
// Get root directory
utility::fileSystemFactory* fsf = platform::getHandler()->getFileSystemFactory();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
m_fsPath = fsf->stringToPath(GET_PROPERTY(string, PROPERTY_SERVER_ROOTPATH));

View File

@ -55,18 +55,14 @@ posixHandler::posixHandler()
m_socketFactory = vmime::create <posixSocketFactory>();
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
m_fileSysFactory = new posixFileSystemFactory();
m_childProcFactory = new posixChildProcessFactory();
m_fileSysFactory = vmime::create <posixFileSystemFactory>();
m_childProcFactory = vmime::create <posixChildProcessFactory>();
#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 <vmime::net::socketFactory> posixHandler::getSocketFactory() const
ref <vmime::net::socketFactory> posixHandler::getSocketFactory()
{
return m_socketFactory.dynamicCast <vmime::net::socketFactory>();
return m_socketFactory;
}
#endif
@ -183,15 +179,15 @@ ref <vmime::net::socketFactory> posixHandler::getSocketFactory() const
#if VMIME_HAVE_FILESYSTEM_FEATURES
vmime::utility::fileSystemFactory* posixHandler::getFileSystemFactory() const
ref <vmime::utility::fileSystemFactory> posixHandler::getFileSystemFactory()
{
return (m_fileSysFactory);
return m_fileSysFactory;
}
vmime::utility::childProcessFactory* posixHandler::getChildProcessFactory() const
ref <vmime::utility::childProcessFactory> posixHandler::getChildProcessFactory()
{
return (m_childProcFactory);
return m_childProcFactory;
}
#endif

View File

@ -49,17 +49,13 @@ windowsHandler::windowsHandler()
m_socketFactory = vmime::create <windowsSocketFactory>();
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
m_fileSysFactory = new windowsFileSystemFactory();
m_fileSysFactory = vmime::create <windowsFileSystemFactory>();
#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 <vmime::net::socketFactory> windowsHandler::getSocketFactory() const
ref <vmime::net::socketFactory> windowsHandler::getSocketFactory()
{
return m_socketFactory.dynamicCast <vmime::net::socketFactory>();
return m_socketFactory;
}
#endif
@ -250,13 +246,13 @@ ref <vmime::net::socketFactory> windowsHandler::getSocketFactory() const
#if VMIME_HAVE_FILESYSTEM_FEATURES
vmime::utility::fileSystemFactory* windowsHandler::getFileSystemFactory() const
ref <vmime::utility::fileSystemFactory> windowsHandler::getFileSystemFactory()
{
return (m_fileSysFactory);
return m_fileSysFactory;
}
vmime::utility::childProcessFactory* windowsHandler::getChildProcessFactory() const
ref <vmime::utility::childProcessFactory> windowsHandler::getChildProcessFactory()
{
// TODO: Not implemented
return (NULL);

View File

@ -501,7 +501,7 @@ private:
const vmime::utility::url getStoreURL()
{
vmime::utility::fileSystemFactory* fsf =
vmime::ref <vmime::utility::fileSystemFactory> fsf =
vmime::platform::getHandler()->getFileSystemFactory();
vmime::utility::url url(std::string("maildir://localhost")
@ -512,7 +512,7 @@ private:
void createMaildir(const vmime::string* const dirs, const vmime::string* const files)
{
vmime::utility::fileSystemFactory* fsf =
vmime::ref <vmime::utility::fileSystemFactory> fsf =
vmime::platform::getHandler()->getFileSystemFactory();
vmime::ref <vmime::utility::file> rootDir = fsf->create(m_tempPath);
@ -544,7 +544,7 @@ private:
void destroyMaildir()
{
vmime::utility::fileSystemFactory* fsf =
vmime::ref <vmime::utility::fileSystemFactory> fsf =
vmime::platform::getHandler()->getFileSystemFactory();
recursiveDelete(fsf->create(m_tempPath));

View File

@ -108,7 +108,7 @@ public:
*
* @return socket factory
*/
virtual ref <net::socketFactory> getSocketFactory() const = 0;
virtual ref <net::socketFactory> getSocketFactory() = 0;
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
@ -116,14 +116,14 @@ public:
*
* @return file-system factory
*/
virtual utility::fileSystemFactory* getFileSystemFactory() const = 0;
virtual ref <utility::fileSystemFactory> getFileSystemFactory() = 0;
/** Return a pointer to a factory that creates child process objects,
* which are used to spawn processes (run executable files).
*
* @return child process factory
*/
virtual utility::childProcessFactory* getChildProcessFactory() const = 0;
virtual ref <utility::childProcessFactory> getChildProcessFactory() = 0;
#endif
};
@ -135,7 +135,7 @@ public:
sm_handler = vmime::create <TYPE>();
}
static ref <const handler> getHandler()
static ref <handler> getHandler()
{
if (!sm_handler)
throw exceptions::no_platform_handler();

View File

@ -61,13 +61,13 @@ public:
unsigned int getProcessId() const;
#if VMIME_HAVE_MESSAGING_FEATURES
ref <vmime::net::socketFactory> getSocketFactory() const;
ref <vmime::net::socketFactory> getSocketFactory();
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
vmime::utility::fileSystemFactory* getFileSystemFactory() const;
ref <vmime::utility::fileSystemFactory> getFileSystemFactory();
vmime::utility::childProcessFactory* getChildProcessFactory() const;
ref <vmime::utility::childProcessFactory> getChildProcessFactory();
#endif
void wait() const;
@ -79,8 +79,8 @@ private:
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
posixFileSystemFactory* m_fileSysFactory;
posixChildProcessFactory* m_childProcFactory;
ref <posixFileSystemFactory> m_fileSysFactory;
ref <posixChildProcessFactory> m_childProcFactory;
#endif
};

View File

@ -60,13 +60,13 @@ public:
unsigned int getProcessId() const;
#if VMIME_HAVE_MESSAGING_FEATURES
ref <vmime::net::socketFactory> getSocketFactory() const;
ref <vmime::net::socketFactory> getSocketFactory();
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
vmime::utility::fileSystemFactory* getFileSystemFactory() const;
ref <vmime::utility::fileSystemFactory> getFileSystemFactory();
vmime::utility::childProcessFactory* getChildProcessFactory() const;
ref <vmime::utility::childProcessFactory> getChildProcessFactory();
#endif
void wait() const;
@ -78,7 +78,7 @@ private:
#endif
#if VMIME_HAVE_FILESYSTEM_FEATURES
windowsFileSystemFactory* m_fileSysFactory;
ref <windowsFileSystemFactory> m_fileSysFactory;
#endif
};

View File

@ -85,7 +85,7 @@ public:
/** Create 'childProcess' objects.
*/
class childProcessFactory
class childProcessFactory : public object
{
public:

View File

@ -214,7 +214,7 @@ private:
/** Constructs 'file' objects.
*/
class fileSystemFactory
class fileSystemFactory : public object
{
public: