Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory fix #11331

Merged
merged 9 commits into from
Mar 6, 2023
Merged

Memory fix #11331

merged 9 commits into from
Mar 6, 2023

Conversation

daschuer
Copy link
Member

@daschuer daschuer commented Mar 5, 2023

Some more memory fixes discovered by Valgrind.

@@ -38,6 +38,7 @@ ControlDoublePrivate::ControlDoublePrivate()
Stat::SAMPLE_VARIANCE | Stat::MIN | Stat::MAX),
// default CO is read only
m_confirmRequired(true) {
m_value.setValue(0.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This silences just the valgrind warning and make the bug itself invisible for code analysis. The root cause must be somewhere in the use of the overloaded classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the value of the constant default ControlObject that is used whenever there is no real control object.
This has been introduced to get around many null checks when dealing with control objects.
The original issue happens here:

if (m_currentPageControl.get() == index) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than you must set the correct value (might be 0 here), in the class, where the original issue occured.
Otherwise you make Valgrind blind for bugs of the same kind in other classes. And it depends on the context, if 0 is the correct value there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only have a single Default Control object for all, and it is const:

QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getDefaultControl() {

So it should have a reasonable default of 0 instead of a random value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only important point is: Never initialize with dummy values!
Which implies to not initialize in the base class, do this in /src/widget/wwidgetstack.cpp instead.
Otherwise Valgrind will be blind for "Use Of Uninitialiezd Variable" bugs introduced in future.
Valgrind can not distinguish between initialization with dummy values and intialize with real values. But it can detect code pathes, were the variable is used before initialization. Therefore always initializes with the real value, which is correct in the specific context - than Valgrind, ASAN and statical code analysis tools like cppcheck will detect the real bugs in other paths.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm the rule in general. But in this case the whole ContrObject is a singleton read only dummy. There is no point of a business logic value initialization and you demand is not possible here.
The control object system has already warnings if a control uses the default CO unintentionally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are already warnings in place, this is of cause Ok here.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. A couple minor tweaks I noticed.

@daschuer
Copy link
Member Author

daschuer commented Mar 6, 2023

OK, than this is ready for merge.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, waiting for @JoergAtGithub to resolve his review and merge.

@daschuer daschuer changed the base branch from main to 2.4 March 6, 2023 17:14
@JoergAtGithub JoergAtGithub merged commit 8d435da into mixxxdj:2.4 Mar 6, 2023
@JoergAtGithub
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants