Skip to content

Commit

Permalink
Fixed|libcore: Fixed resource leaks
Browse files Browse the repository at this point in the history
When creating an object in the_Foundation, it has a reference count of 1. tF::make_ref() takes ownership of that existing reference.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent bac9874 commit 3cbfe94
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions doomsday/apps/gloom/src/gloomapp.cpp
Expand Up @@ -44,7 +44,7 @@ static const duint16 COMMAND_PORT = 14666;
DE_PIMPL(GloomApp)
{
ImageBank images;
tF::ref<iDatagram> commandSocket;
tF::ref<iDatagram> commandSocket;
Beacon beacon{{COMMAND_PORT, COMMAND_PORT + 4}};
std::unique_ptr<AppWindowSystem> winSys;
std::unique_ptr<AudioSystem> audioSys;
Expand All @@ -59,7 +59,7 @@ DE_PIMPL(GloomApp)

// GloomEd will tell us what to do via the command socket.
{
commandSocket.reset(new_Datagram());
commandSocket = tF::make_ref(new_Datagram());
setUserData_Object(commandSocket, this);
iConnect(Datagram, commandSocket, message, commandSocket, receivedRemoteCommand);
for (int attempt = 0; attempt < 12; ++attempt)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/comms/src/localserver.cpp
Expand Up @@ -149,7 +149,7 @@ void LocalServer::start(duint16 port,
LOG_NET_NOTE("Starting local server on port %i using game mode '%s'")
<< port << gameMode;

d->proc.reset(cmd.executeProcess());
d->proc = tF::make_ref(cmd.executeProcess());
}

void LocalServer::stop()
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/concurrency/thread.cpp
Expand Up @@ -41,7 +41,7 @@ DE_PIMPL(Thread)

Impl(Public *i) : Base(i)
{
thread.reset(new_Thread(runFunc));
thread = tF::make_ref(new_Thread(runFunc));
setUserData_Thread(thread, this);
{
auto &kt = knownThreads();
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libs/core/src/core/commandline.cpp
Expand Up @@ -124,7 +124,7 @@ DE_PIMPL(CommandLine)
iProcess *proc = new_Process();
setWorkingDirectory_Process(proc, initialDir.toString());

tF::ref<iStringList> args{new_StringList()};
auto args = tF::make_ref(new_StringList());
for (dsize i = 0; i < self().count(); ++i)
{
pushBack_StringList(args, self().at(i));
Expand Down Expand Up @@ -487,7 +487,7 @@ bool CommandLine::execute() const
{
LOG_AS("CommandLine");

tF::ref<iProcess> proc{d->execute()};
auto proc = tF::make_ref(d->execute());
if (!proc)
{
LOG_ERROR("Failed to start \"%s\"") << at(0);
Expand All @@ -496,10 +496,10 @@ bool CommandLine::execute() const
LOG_DEBUG("Started detached process %i \"%s\"") << pid_Process(proc) << at(0);
return true;
}

bool CommandLine::executeAndWait(String *output) const
{
tF::ref<iProcess> proc{d->execute()};
auto proc = tF::make_ref(d->execute());
if (!proc)
{
return false;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/data/regexp.cpp
Expand Up @@ -63,8 +63,8 @@ const RegExp RegExp::WHITESPACE{"\\s+"};

RegExp::RegExp(const String &expression, Sensitivity cs)
{
_d.reset(new_RegExp(expression, cs == CaseSensitive ? caseSensitive_RegExpOption
: caseInsensitive_RegExpOption));
_d = tF::make_ref(new_RegExp(expression, cs == CaseSensitive ? caseSensitive_RegExpOption
: caseInsensitive_RegExpOption));
}

bool RegExp::exactMatch(const String &subject) const
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/filesys/directoryfeed.cpp
Expand Up @@ -92,7 +92,7 @@ Feed::PopulatedFiles DirectoryFeed::populate(Folder const &folder)

PopulatedFiles populated;

tF::ref<iDirFileInfo> dirInfo(new_DirFileInfo(d->nativePath.toString()));
auto dirInfo = tF::make_ref(new_DirFileInfo(d->nativePath.toString()));
iForEach(DirFileInfo, i, dirInfo)
{
const NativePath path(String(path_FileInfo(i.value)));
Expand Down Expand Up @@ -286,7 +286,7 @@ void DirectoryFeed::changeWorkingDir(NativePath const &nativePath)

File::Status DirectoryFeed::fileStatus(NativePath const &nativePath)
{
tF::ref<iFileInfo> info(new_FileInfo(nativePath.toString()));
auto info = tF::make_ref(new_FileInfo(nativePath.toString()));
if (!exists_FileInfo(info))
{
/// @throw StatusError Determining the file status was not possible.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/filesys/nativepath.cpp
Expand Up @@ -162,7 +162,7 @@ bool NativePath::isRelative() const

bool NativePath::isDirectory() const
{
tF::ref<iFileInfo> i(new_FileInfo(toString()));
auto i = tF::make_ref(new_FileInfo(toString()));
return exists_FileInfo(i) && isDirectory_FileInfo(i);
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/net/address.cpp
Expand Up @@ -48,7 +48,7 @@ Address::Address() : d(new Impl)

Address::Address(char const *address, duint16 port) : d(new Impl)
{
d->addr.reset(new_Address());
d->addr = tF::make_ref(new_Address());
d->port = port;
lookupTcpCStr_Address(d->addr, address, port);
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/net/beacon.cpp
Expand Up @@ -168,7 +168,7 @@ void Beacon::start()
{
DE_ASSERT(!d->socket);

d->socket.reset(new_Datagram());
d->socket = tF::make_ref(new_Datagram());
setUserData_Object(d->socket, d);
iConnect(Datagram, d->socket, message, d->socket, Impl::readIncoming);

Expand Down Expand Up @@ -232,7 +232,7 @@ void Beacon::discover(const TimeSpan& timeOut, const TimeSpan& interval)
d->broadcastAddresses.clear();
for (duint p = d->udpPorts.start; p < d->udpPorts.end; ++p)
{
d->broadcastAddresses << tF::ref<iAddress>{newBroadcast_Address(duint16(p))};
d->broadcastAddresses << tF::make_ref(newBroadcast_Address(duint16(p)));
}

// Time-out timer.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/net/listensocket.cpp
Expand Up @@ -61,7 +61,7 @@ ListenSocket::ListenSocket(duint16 port) : d(new Impl(this))
{
LOG_AS("ListenSocket");

d->service.reset(new_Service(port));
d->service = tF::make_ref(new_Service(port));
d->port = port;
setUserData_Object(d->service, d);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/net/networkinterfaces.cpp
Expand Up @@ -82,7 +82,7 @@ DE_PIMPL_NOREF(NetworkInterfaces), public Lockable
void update()
{
interfaces.clear();
tF::ref<iObjectList> infs(networkInterfaces_Address());
auto infs = tF::make_ref(networkInterfaces_Address());
iConstForEach(ObjectList, i, infs)
{
interfaces << Address(reinterpret_cast<const iAddress *>(i.object));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/net/socket.cpp
Expand Up @@ -571,7 +571,7 @@ void Socket::open(Address const &address) // non-blocking
if (!d->quiet) LOG_NET_MSG("Opening connection to %s") << address.asText();

d->peer = address;
d->socket.reset(newAddress_Socket(address));
d->socket = tF::make_ref(newAddress_Socket(address));
initialize();

// Now that the signals have been set...
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/net/webrequest.cpp
Expand Up @@ -40,7 +40,7 @@ DE_PIMPL(WebRequest), public Lockable, public AsyncScope

Impl(Public *i) : Base(i)
{
web.reset(new_WebRequest());
web = tF::make_ref(new_WebRequest());
setUserData_Object(web, this);
iConnect(WebRequest, web, progress, web, notifyProgress);
iConnect(WebRequest, web, readyRead, web, notifyReadyRead);
Expand Down

0 comments on commit 3cbfe94

Please sign in to comment.