Fix memory errors caused by using dangling pointers to SensorClients in SensorAgent
Needs ReviewPublic

Authored by jpalecek on Mon, May 11, 1:46 AM.

Details

Summary

When some SensorClients are destroyed, eg. when KSysguard is closed,
they fail to deregister themselves from SensorAgent. This may cause a
crash when further messages arrive for them. This patch fixes that.

BUG: 350140

Diff Detail

Repository
R106 KSysguard
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 26727
Build 26745: arc lint + arc unit
jpalecek created this revision.Mon, May 11, 1:46 AM
Restricted Application added a project: Plasma. · View Herald TranscriptMon, May 11, 1:46 AM
jpalecek requested review of this revision.Mon, May 11, 1:46 AM
anthonyfieroni added inline comments.
gui/SensorBrowser.cpp
49

When you delete the map content, all agents should loose their connections, no?

jpalecek added inline comments.Mon, May 11, 1:14 PM
gui/SensorBrowser.cpp
49

No, it only deletes the HostInfo structure. See the source. It doesn't disconnect anything. Nor does deleting this, as the Agent holds the client as a bare pointer, it can't know that it ceased to exist. It isn't even a QPointer (probably bc. SensorClient isn't a QObject).

ahiemstra requested changes to this revision.Mon, May 11, 2:20 PM
ahiemstra added inline comments.
gui/SensorBrowser.cpp
49

I agree with Anthony though, if you delete a hostInfo it _should_ remove its connection. So it's better to move this code into a destructor for HostInfo.

gui/ksysguard.cpp
153

Coding style: Single line ifs still need braces and should not be on a single line.

This revision now requires changes to proceed.Mon, May 11, 2:20 PM
jpalecek added inline comments.Mon, May 11, 2:40 PM
gui/SensorBrowser.cpp
49

But the host info, at least in its present form, doesn't have the client pointer to pass to disconnectClient. But I can see your point, I will change it.

jpalecek updated this revision to Diff 82568.Mon, May 11, 4:45 PM

Move the client deregistering code from SensorBrowserModel to HostInfo

Also remove the clear function. After investigating further, I've
found out it suffers from the same problem, that it doesn't deregister
from the hosts it removes. On top of that, it leaves dangling pointers
in mSensorInfoMap. It doesn't really clear all the other internal
structures. And it is never used. So I think it's best to delete it.

jpalecek marked 5 inline comments as done.Sat, May 16, 12:31 AM