mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix some memory leaks and fix #1038
This commit is contained in:
parent
8876dad457
commit
d35ebb22f0
|
@ -64,6 +64,15 @@ Audio& Audio::getInstance()
|
|||
return *instance;
|
||||
}
|
||||
|
||||
Audio::~Audio()
|
||||
{
|
||||
audioThread->wait(100);
|
||||
audioThread->terminate();
|
||||
delete audioThread;
|
||||
delete audioInLock;
|
||||
delete audioOutLock;
|
||||
}
|
||||
|
||||
void Audio::suscribeInput()
|
||||
{
|
||||
if (!alInDev)
|
||||
|
|
|
@ -76,6 +76,7 @@ public:
|
|||
|
||||
private:
|
||||
explicit Audio()=default;
|
||||
~Audio();
|
||||
static void playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate);
|
||||
|
||||
private:
|
||||
|
|
26
src/core.cpp
26
src/core.cpp
|
@ -95,6 +95,13 @@ Core::~Core()
|
|||
clearPassword(Core::ptMain);
|
||||
clearPassword(Core::ptHistory);
|
||||
|
||||
toxTimer->stop();
|
||||
coreThread->exit(0);
|
||||
qApp->processEvents();
|
||||
coreThread->wait(500);
|
||||
if (coreThread->isRunning())
|
||||
coreThread->terminate();
|
||||
|
||||
if (tox)
|
||||
{
|
||||
toxav_kill(toxav);
|
||||
|
@ -1295,6 +1302,9 @@ bool Core::loadConfiguration(QString path)
|
|||
|
||||
void Core::saveConfiguration()
|
||||
{
|
||||
if (QThread::currentThread() != coreThread)
|
||||
return (void) QMetaObject::invokeMethod(this, "saveConfiguration");
|
||||
|
||||
QString dir = Settings::getSettingsDirPath();
|
||||
QDir directory(dir);
|
||||
if (!directory.exists() && !directory.mkpath(directory.absolutePath())) {
|
||||
|
@ -1321,6 +1331,9 @@ void Core::saveConfiguration()
|
|||
|
||||
void Core::saveConfiguration(const QString& path)
|
||||
{
|
||||
if (QThread::currentThread() != coreThread)
|
||||
return (void) QMetaObject::invokeMethod(this, "saveConfiguration", Q_ARG(const QString&, path));
|
||||
|
||||
if (!tox)
|
||||
{
|
||||
qWarning() << "Core::saveConfiguration: Tox not started, aborting!";
|
||||
|
@ -1330,27 +1343,28 @@ void Core::saveConfiguration(const QString& path)
|
|||
Settings::getInstance().save();
|
||||
|
||||
QSaveFile configurationFile(path);
|
||||
if (!configurationFile.open(QIODevice::WriteOnly)) {
|
||||
if (!configurationFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
qCritical() << "File " << path << " cannot be opened";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Core: writing tox_save to " << path;
|
||||
|
||||
uint32_t fileSize; bool encrypt = Settings::getInstance().getEncryptTox();
|
||||
uint32_t fileSize;
|
||||
bool encrypt = Settings::getInstance().getEncryptTox();
|
||||
if (encrypt)
|
||||
fileSize = tox_encrypted_size(tox);
|
||||
else
|
||||
fileSize = tox_size(tox);
|
||||
|
||||
if (fileSize > 0 && fileSize <= INT32_MAX) {
|
||||
if (fileSize > 0 && fileSize <= INT32_MAX)
|
||||
{
|
||||
uint8_t *data = new uint8_t[fileSize];
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
if (!pwsaltedkeys[ptMain])
|
||||
{
|
||||
// probably zero chance event
|
||||
Widget::getInstance()->showWarningMsgBox(tr("NO Password"), tr("Will be saved without encryption!"));
|
||||
tox_save(tox, data);
|
||||
}
|
||||
|
@ -1365,7 +1379,9 @@ void Core::saveConfiguration(const QString& path)
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tox_save(tox, data);
|
||||
}
|
||||
|
||||
configurationFile.write(reinterpret_cast<char *>(data), fileSize);
|
||||
configurationFile.commit();
|
||||
|
|
|
@ -64,9 +64,6 @@ public:
|
|||
bool hasFriendWithPublicKey(const QString &pubkey) const; ///< Check if we have a friend by public key
|
||||
int joinGroupchat(int32_t friendNumber, uint8_t type, const uint8_t* pubkey,uint16_t length) const; ///< Accept a groupchat invite
|
||||
void quitGroupChat(int groupId) const; ///< Quit a groupchat
|
||||
|
||||
void saveConfiguration();
|
||||
void saveConfiguration(const QString& path);
|
||||
|
||||
QString getIDString() const; ///< Get the 12 first characters of our Tox ID
|
||||
|
||||
|
@ -88,6 +85,9 @@ public slots:
|
|||
void bootstrapDht(); ///< Connects us to the Tox network
|
||||
void switchConfiguration(const QString& profile); ///< Load a different profile and restart the core
|
||||
|
||||
void saveConfiguration();
|
||||
void saveConfiguration(const QString& path);
|
||||
|
||||
void acceptFriendRequest(const QString& userId);
|
||||
void requestFriendship(const QString& friendAddress, const QString& message);
|
||||
void groupInviteFriend(int friendId, int groupId);
|
||||
|
|
|
@ -315,16 +315,18 @@ void Widget::updateTrayIcon()
|
|||
Widget::~Widget()
|
||||
{
|
||||
core->saveConfiguration();
|
||||
coreThread->exit();
|
||||
coreThread->wait(500); // In case of deadlock (can happen with QtAudio/PA bugs)
|
||||
if (!coreThread->isFinished())
|
||||
coreThread->terminate();
|
||||
AutoUpdater::abortUpdates();
|
||||
delete core;
|
||||
hideMainForms();
|
||||
delete settingsWidget;
|
||||
delete addFriendForm;
|
||||
delete filesForm;
|
||||
delete idleTimer;
|
||||
|
||||
if (ui->mainHead->style())
|
||||
delete ui->mainHead->style();
|
||||
if (ui->mainContent->style())
|
||||
delete ui->mainContent->style();
|
||||
FriendList::clear();
|
||||
GroupList::clear();
|
||||
delete trayMenu;
|
||||
|
|
Loading…
Reference in New Issue
Block a user