Skip to content

Commit

Permalink
MusPlayQt: Fixed memory leak at SingleApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed Jun 2, 2023
1 parent 0219d40 commit d4bc34a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
20 changes: 11 additions & 9 deletions examples/MusPlay-Qt/SingleApplication/singleapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ SingleApplication::SingleApplication(QStringList &args) :
{
m_shouldContinue = false; // By default this is not the main process

m_socket = new QUdpSocket();
m_server = nullptr;
QString isServerRuns;

Expand Down Expand Up @@ -70,11 +69,11 @@ SingleApplication::SingleApplication(QStringList &args) :
acceptor.bind(QHostAddress::LocalHost, 58235, QUdpSocket::ReuseAddressHint|QUdpSocket::ShareAddress);

// Attempt to connect to the LocalServer
m_socket->connectToHost(QHostAddress::LocalHost, 58234);
if(m_socket->waitForConnected(100))
m_socket.connectToHost(QHostAddress::LocalHost, 58234);
if(m_socket.waitForConnected(100))
{
m_socket->write(QString("CMD:Is SDL2 Mixer X running?").toUtf8());
m_socket->flush();
m_socket.write(QString("CMD:Is SDL2 Mixer X running?").toUtf8());
m_socket.flush();
if(acceptor.waitForReadyRead(100))
{
//QByteArray dataGram;//Yes, I'm runs!
Expand All @@ -99,6 +98,7 @@ SingleApplication::SingleApplication(QStringList &args) :
isServerRuns.clear();
args.removeAll("--force-run");
}

m_arguments = args;

if(isRunning)
Expand All @@ -108,10 +108,10 @@ SingleApplication::SingleApplication(QStringList &args) :
for(int i = 1; i < m_arguments.size(); i++)
str.append(QString("\n%1").arg(m_arguments[i]));
bytes = str.toUtf8();
m_socket->write(bytes);
m_socket->flush();
m_socket.write(bytes);
m_socket.flush();
QThread::msleep(100);
m_socket->close();
m_socket.close();
}
else
{
Expand Down Expand Up @@ -149,7 +149,9 @@ SingleApplication::~SingleApplication()
qDebug() << "Terminated!";
}
}
if(m_server) delete m_server;

if(m_server)
delete m_server;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions examples/MusPlay-Qt/SingleApplication/singleapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
class SingleApplication : public QObject
{
Q_OBJECT

public:
explicit SingleApplication(QStringList &args);
~SingleApplication();
bool shouldContinue();
QStringList arguments();

public slots:

signals:
void showUp();
void stopServer();
Expand All @@ -41,7 +40,7 @@ private slots:
//! Shared memory, stable way to avoid concurrent running multiple copies of same application
QSharedMemory m_shmem;
//! Client socket pointer
QUdpSocket* m_socket;
QUdpSocket m_socket;
//! Pointer to currently working local server copy
LocalServer* m_server;
//! Recently accepted arguments
Expand Down

0 comments on commit d4bc34a

Please sign in to comment.