Fixing various coding problems found with static code analysis tools.
ClosedPublic

Authored by abika on Jul 8 2016, 12:36 PM.

Details

Summary

Fixing minor memory leak.

Cleanup of unused class declarations

Cleanup of unused #includes

Cleanup of invalid forward declarations

Cleanup of duplicate #includes

Cleanup of unused variable

Cleanup of duplicate declarations

Cleanup of obsolete forward declaration

Test Plan

Still compiles .)

Diff Detail

Repository
R167 Krusader
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
abika updated this revision to Diff 5020.Jul 8 2016, 12:36 PM
abika retitled this revision from to Fixing various coding problems found with static code analysis tools..
abika updated this object.
abika edited the test plan for this revision. (Show Details)
abika added a reviewer: Krusader.
asensi added a subscriber: asensi.Jul 8 2016, 6:44 PM

Fixing various coding problems found with static code analysis tools.

Great! Thank you very much, Alex, for using those tools.

The resulting code compiles using Kubuntu 16.04 in a virtual machine, although I would like that someone else reviews the delete proc; line that was added to krusader/UserAction/kractionbase.cpp . With the new changes applied, If I put the cursor on
a .cpp file and then I go to

UserActions > Multimedia > Enqueue in Amarok

then Krusader seems to crash. However, if I delete the delete proc; line and I try it again, then Krusader keeps being alive :-) although in the command line it was written:

/bin/sh: 1: amarok: not found

as it was expected in that virtual machine because Amarok was not installed.

asensi added a comment.Jul 9 2016, 8:31 AM

Additional information:

To perform some tests today I added

qDebug() << "======> A new KrActionProc was made." << endl;

to

KrActionProc::KrActionProc(KrActionBase* action)

and I added

qDebug() << "======> A KrActionProc was deleted." << endl;

to

KrActionProc::~KrActionProc()

Then I repeated the last test ("UserActions > Multimedia > Enqueue in Amarok", etc. while having the forementioned delete proc; line); this was seen in the command line:

$ /usr/bin/krusader
[...]
======> A new KrActionProc was made. 

======> A KrActionProc was deleted. 

QProcess: Destroyed while process ("/bin/sh") is still running.
======> A KrActionProc was deleted. 

and Krusader seemed to crash (note: two "was deleted" messages were seen but only one "A new" message was seen). I erased the delete proc; line, I repeated the test, then in the command line it was seen what it was expected:

======> A new KrActionProc was made. 

/bin/sh: 1: amarok: not found
======> A KrActionProc was deleted.

and Krusader was still "alive" :-). I made similar tests using the useraction "Edit as root" and it had similar results. So it seems that that delete proc; line is not needed, but it would be good if other developers talk about this :-)

abika added a comment.Jul 10 2016, 9:56 AM

well damn, I shouldn't have easily trust an algorithm for detecting coding problems (cppcheck).

delete proc is wrong for sure, I simply didn't see that in KrActionProc::start() a new thread is started.

But I can't confirm that proc is ever deleted (without delete proc). My test was the same but there wasn't anything printed from KrActionProc::~KrActionProc().

However, instead proc->deleteLater() should do the trick. Qt docs confirm this:

Since Qt 4.8, if deleteLater() is called on an object that lives in a thread with no running event loop, the object will be destroyed when the thread finishes.

Could you guys check that again? And thanks, its always good to know that somebody spots the mistakes that I might do!

asensi added a comment.EditedJul 14 2016, 8:03 PM

To perform some tests today I also deleted the delete proc; line, I also added

qDebug() << "======> A new KrActionProc was made." << endl;

to

KrActionProc::KrActionProc(KrActionBase* action)

and I also added

qDebug() << "======> A KrActionProc was deleted." << endl;

to

KrActionProc::~KrActionProc()

Then I repeated the last test ("UserActions > Multimedia > Enqueue in Amarok" while having the Krusader cursor on a .cpp file) and this was also seen in the command line:

$ /usr/bin/krusader
======> A new KrActionProc was made. 

/bin/sh: 1: amarok: not found
======> A KrActionProc was deleted. 

However, if I used proc->deleteLater() in the place of the delete proc;, then the results were:

$ /usr/bin/krusader
======> A new KrActionProc was made. 

======> A KrActionProc was deleted. 

QProcess: Destroyed while process ("/bin/sh") is still running.
======> A KrActionProc was deleted. 

and later Krusader crashed :-(

abika added a comment.Jul 15 2016, 1:30 PM

oh wow, finally found it: in my configuration the workdir set for the useraction was invalid. In this case the command is not executed and proc is not deleted.

I'll revert the deletion. And thanks for testing again!

abika updated this revision to Diff 5208.Jul 15 2016, 1:32 PM
  • Revert "Fixing minor memory leak."
asensi accepted this revision.Jul 15 2016, 1:57 PM
asensi added a reviewer: asensi.

And thanks for testing again!

Thank you for all :-)

This revision is now accepted and ready to land.Jul 15 2016, 1:57 PM
Closed by commit R167:a9a18f758894: Fixing various coding problems found with static code analysis tools. (authored by Alexander Bikadorov <bikaejkb@mailbox.tu-berlin.de>). · Explain WhyJul 15 2016, 2:29 PM
This revision was automatically updated to reflect the committed changes.