Fix SharedNodePointer leak

This commit is contained in:
Atlante45 2017-06-06 19:04:12 -07:00
parent 1baff8af33
commit 61eb93af35
4 changed files with 17 additions and 9 deletions

View file

@ -584,7 +584,7 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
return matchingNode;
} else {
// we didn't have this node, so add them
Node* newNode = new Node(uuid, nodeType, publicSocket, localSocket, permissions, connectionSecret, this);
Node* newNode = new Node(uuid, nodeType, publicSocket, localSocket, permissions, connectionSecret);
if (nodeType == NodeType::AudioMixer) {
LimitedNodeList::flagTimeForConnectionStep(LimitedNodeList::AddedAudioMixer);
@ -617,24 +617,28 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
}
// insert the new node and release our read lock
_nodeHash.insert(UUIDNodePair(newNode->getUUID(), newNodePointer));
_nodeHash.emplace(newNode->getUUID(), newNodePointer);
readLocker.unlock();
qCDebug(networking) << "Added" << *newNode;
auto weakPtr = newNodePointer.toWeakRef(); // We don't want the lambdas to hold a strong ref
emit nodeAdded(newNodePointer);
if (newNodePointer->getActiveSocket()) {
emit nodeActivated(newNodePointer);
} else {
connect(newNodePointer.data(), &NetworkPeer::socketActivated, this, [=] {
emit nodeActivated(newNodePointer);
disconnect(newNodePointer.data(), &NetworkPeer::socketActivated, this, 0);
connect(newNodePointer.data(), &NetworkPeer::socketActivated, this, [this, weakPtr] {
auto sharedPtr = weakPtr.lock();
if (sharedPtr) {
emit nodeActivated(sharedPtr);
disconnect(sharedPtr.data(), &NetworkPeer::socketActivated, this, 0);
}
});
}
// Signal when a socket changes, so we can start the hole punch over.
auto weakPtr = newNodePointer.toWeakRef(); // We don't want the lambda to hold a strong ref
connect(newNodePointer.data(), &NetworkPeer::socketUpdated, this, [=] {
connect(newNodePointer.data(), &NetworkPeer::socketUpdated, this, [this, weakPtr] {
emit nodeSocketUpdated(weakPtr);
});

View file

@ -40,7 +40,7 @@ public:
Node(const QUuid& uuid, NodeType_t type,
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket,
const NodePermissions& permissions, const QUuid& connectionSecret = QUuid(),
QObject* parent = 0);
QObject* parent = nullptr);
bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; }
bool operator!=(const Node& otherNode) const { return !(*this == otherNode); }

View file

@ -20,6 +20,8 @@
class ReceivedPacketProcessor : public GenericThread {
Q_OBJECT
public:
static const unsigned long MAX_WAIT_TIME { 100 };
ReceivedPacketProcessor();
/// Add packet from network receive thread to the processing queue.
@ -64,7 +66,7 @@ protected:
virtual bool process() override;
/// Determines the timeout of the wait when there are no packets to process. Default value means no timeout
virtual unsigned long getMaxWait() const { return ULONG_MAX; }
virtual unsigned long getMaxWait() const { return MAX_WAIT_TIME; }
/// Override to do work before the packets processing loop. Default does nothing.
virtual void preProcess() { }

View file

@ -10,6 +10,7 @@
//
#include <QDebug>
#include <QtCore/QCoreApplication>
#include "GenericThread.h"
@ -73,6 +74,7 @@ void GenericThread::threadRoutine() {
}
while (!_stopThread) {
QCoreApplication::processEvents();
// override this function to do whatever your class actually does, return false to exit thread early
if (!process()) {