Fix possible memleaks occuring when passing nonexistent dirs to console library creator. (#132)

This commit is contained in:
Felix Kauselmann 2020-07-02 20:28:53 +02:00 committed by GitHub
parent 868843df37
commit 41ccef1060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,21 +12,21 @@ ConsoleUILibraryCreator::ConsoleUILibraryCreator(QObject *parent)
void ConsoleUILibraryCreator::createLibrary(const QString &name, const QString &path)
{
QEventLoop eventLoop;
LibraryCreator *libraryCreator = new LibraryCreator();
QDir pathDir(path);
if (!pathDir.exists()) {
std::cout << "Directory not found." << std::endl;
return;
}
QEventLoop eventLoop;
LibraryCreator *libraryCreator = new LibraryCreator();
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
YACReaderLibraries yacreaderLibraries;
yacreaderLibraries.load();
if (yacreaderLibraries.contains(name)) {
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in database." << std::endl;
delete libraryCreator;
return;
}
@ -49,14 +49,14 @@ void ConsoleUILibraryCreator::createLibrary(const QString &name, const QString &
void ConsoleUILibraryCreator::updateLibrary(const QString &path)
{
QEventLoop eventLoop;
LibraryCreator *libraryCreator = new LibraryCreator();
QDir pathDir(path);
if (!pathDir.exists()) {
std::cout << "Directory not found." << std::endl;
return;
}
QEventLoop eventLoop;
LibraryCreator *libraryCreator = new LibraryCreator();
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
libraryCreator->updateLibrary(cleanPath, QDir::cleanPath(pathDir.absolutePath() + "/.yacreaderlibrary"));