Page MenuHomeWildfire Games

Fix reported memory leaks in the glooxwrapper following rP19703
ClosedPublic

Authored by JoshuaJB on Jul 17 2019, 9:49 PM.

Details

Summary

A few memory leaks were left unaddressed in rP19703. This patch either fixes them or removes the unused code they were a part of.

Test Plan

Check that one can host a game through the lobby with STUN

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 8433
Build 13777: Vulcan BuildJenkins

Event Timeline

JoshuaJB created this revision.Jul 17 2019, 9:49 PM

Build failure - The Moirai have given mortals hearts that can endure.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/118/display/redirect

JoshuaJB updated this revision to Diff 8966.Jul 17 2019, 10:01 PM

Change the diff to be from the repository root rather than the source folder.

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

source/lobby/glooxwrapper/glooxwrapper.h
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/lobby/glooxwrapper/glooxwrapper.h
|  88| namespace·glooxwrapper
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceglooxwrapper{' is invalid C code. Use --std or --language to configure the language.

source/lobby/XmppClient.cpp
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/lobby/glooxwrapper/glooxwrapper.cpp
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"
Executing section JS...
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/121/display/redirect

JoshuaJB updated this revision to Diff 8967.Jul 17 2019, 10:18 PM

Add copyright year updates

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

source/lobby/glooxwrapper/glooxwrapper.h
|  88| namespace·glooxwrapper
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceglooxwrapper{' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/122/display/redirect

JoshuaJB updated this revision to Diff 8969.Jul 17 2019, 10:27 PM

Remove a superfluous newline and tweak the wording

elexis retitled this revision from Fix some outstanding concerns from rP20582 to Fix few memory leaks in the glooxwrapper following rP20582.Jul 18 2019, 1:37 PM
elexis retitled this revision from Fix few memory leaks in the glooxwrapper following rP20582 to Fix reported memory leaks in the glooxwrapper following rP20582.
elexis retitled this revision from Fix reported memory leaks in the glooxwrapper following rP20582 to Fix reported memory leaks in the glooxwrapper following rP19703.Jul 18 2019, 2:24 PM
elexis edited the summary of this revision. (Show Details)
JoshuaJB updated this revision to Diff 8987.Jul 19 2019, 1:41 AM

Correct the handling of sessionInitiate based off discussions with elexis on IRC yesterday.

elexis accepted this revision.Jul 19 2019, 2:18 PM
elexis added a reviewer: fcxSanya.
elexis added subscribers: fcxSanya, echotangoecho, elexis.

Correctness:
Accepting this since we agreed on IRC to have every author commit the things they came up with, and since every change herein is correct.

Completeness:
There are some more leaks in unused code, that can be identified by crunching the entire file multiple times, see inline comments in rP19703#35141.
The optimistic interpretation is that this patch fixes all(?) leaks in the binary, and the pessimistic interpretation is that the patch missed to find a bunch of memory leaks and that the classes they're in are unused.

Sorry for not having comprehended the glooxwrapper architecture properly. I have gained (1) the necessary experience with memory leaks (as Vladislav ensured that I don't mess these up in some reviews), (2) the necessary knowledge of the gloox codebase (https://bugs.camaya.net/ticket/?id=267 and https://bugs.camaya.net/ticket/?id=280) and (3) learnt from IRC logs why this file exists,
which enabled me to understand fcxSanyas glooxwrapper patch (that I committed here on the a22 feature freeze morning) more, than one I could one year ago (and that's about the time I was in GDPR land or on strike).

As I simultaneously worked on the fix in D2094 as I stopped working on the fixes to other complaints, it seems a bit complaint-driven development, but doesn't change the fact that this
was on my concern list and that I scheduled to go through these before committing new features (that's why we have the concern feature to begin with, it avoids trac tickets for issues with commits).

I accept the patch as it is correct and for the rest of the issues I could fathom in https://code.wildfiregames.com/rP19703#35141 D2094 can be rebased.
I'll add @fcxSanya as a reviewer as he authored the patched patch and might or might not want to contribute to its revision, also @echotangoecho as he pointed out some of the leaks.

source/lobby/XmppClient.cpp
165

Check, this was the most obvious one, and the pointer cannot be avoided since the instantiation depends on other things instantiated in the XmppClient constructor (got the same in D2099?id=8985)

source/lobby/glooxwrapper/glooxwrapper.cpp
289

Check, got the same too in D2099?id=8985 (except for passing the Session and Jingle by reference too)

816

Check, it's unused by 0ad/pyrogenesis and I don't mind reducing the footpring of this file to reduce confusion rather than fixing unused code, got the same in D2099?id=8985.

827

Ack (This was reported rP19703 by echotangoecho, it first got confused in this patch by sessionInitiate taking the Content, but it doesn't take the CandidateList, see the comments for that line in rP19703 and the discussion on IRC on 2019-07-17, otherwise got the same in D2094)

848

I got the same code but a comment for the ICEUDP plugin and a different comment for the Content in D2094.
Also notice that the Content does not delete the pluginList, but only the plugins in the pluginList (the former was assumed at one point).

This is safe as gloox will free Content and the pluginList

to me the comment should be a bit more explicit and tell why the author thinks that gloox deletes that, since it's not in the documentation and since it's not trivial.

	// Content will delete the new ICEUDP plugin in the inherited ~Plugin()
	gloox::Jingle::PluginList pluginList;
	pluginList.push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", candidateList));

	// sessionInitiate deletes the new Content
	return m_Wrapped->sessionInitiate(new gloox::Jingle::Content(std::string("game-data"), pluginList));

The erasure of the ICEUDP plugin was not obvious to us at all and we needed multiple runs to figure it out, so it would be better commented on.

But I'm okay with committing this as is, I can extend the comment in D2094, unless you prefer something else.

(Also I had to lookup C++ specs again to ensure that the Plugin destructor is called, as Content has a custom empty one, but it's fine since all destructors are called without calling them explicitly)

This revision is now accepted and ready to land.Jul 19 2019, 2:18 PM
This revision was automatically updated to reflect the committed changes.