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

mate-session: fix memory leak #285

Merged
merged 1 commit into from
Apr 16, 2023
Merged

mate-session: fix memory leak #285

merged 1 commit into from
Apr 16, 2023

Conversation

rbuj
Copy link
Contributor

@rbuj rbuj commented Oct 23, 2021

No description provided.

Copy link
Member

@lukefromdc lukefromdc left a comment

Choose a reason for hiding this comment

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

While I do NOT know now to properly test these tools, my normal session with compiz starts up same as always with this installed. I can see the memory management changes though and this should work. I am guessing the const portion of these declarations was being tossed by the compiler at build time due to the expected changes of value at runtime.

@lukefromdc lukefromdc requested a review from a team August 19, 2022 00:23
@thesquash
Copy link
Member

I am guessing the const portion of these declarations was being tossed by the compiler at build time due to the expected changes of value at runtime.

Nope. Most people don't know this, but in C, when you add the const qualifier to a pointer variable, the const applies to the thing to which the pointer references, just like the char type name indicates the size of the data pointed to by the pointer. Thus, a pointer of the form const char * p; points to a character variable, and if you attempt to change the value of that pointed-to variable through the pointer, the compiler will warn you. So all of the following would be illegal (or at least warned against by the compiler):

*p = '\0';
p[0] = '\0';
p[i-1] = '\0';

The const specifier does not apply to the pointer variable itself. You can change what the pointer points to at will, even with the const specifier. This is legal:

char a = 'A', b = 'B', c = 'C';
const char * p = &a;
p = &b;
p = &c;

By the way, if you wanted to make the pointer read-only, so that the pointer itself could not be re-assigned the address of some other variable, I think you can apply the const after the last asterisk, like this:

char * const p = &a;

I'm a little rusty on that last point, but it's either that or immediately preceding the asterisk. I think it's after the asterisk, though.

Just thought I'd clear that up, since if any mysteries exist regarding what program code does, the code isn't really getting reviewed, is it?

@lukefromdc
Copy link
Member

Thanks for your explanation of how const was used here, which explains the memory leak. I went to
https://docs.gtk.org/glib/func.clear_pointer.html
which shows g_clear_pointer both destroys the variable and sets the pointer to NULL. This should take care of both the RAM holding the pointer variable and the RAM to which it points, stopping up the leak.

@rbuj rbuj closed this Apr 15, 2023
Copy link
Member

@raveit65 raveit65 left a comment

Choose a reason for hiding this comment

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

LGTM

@raveit65 raveit65 reopened this Apr 16, 2023
@raveit65 raveit65 merged commit 1263384 into master Apr 16, 2023
@raveit65 raveit65 deleted the mate-session-ml branch April 16, 2023 12:32
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.

None yet

4 participants