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

Custom color fixes #187

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Custom color fixes #187

merged 2 commits into from
Nov 4, 2024

Conversation

kadamski
Copy link
Contributor

@kadamski kadamski commented Nov 4, 2024

When trying to rebase my changes on top of the latest master branch, I found out two problems that slipped through the review of PR#185. Fortunately the fixes are rather straightforward.

Krzysztof Adamski added 2 commits November 4, 2024 20:07
In case you don't have custom_color defined in your config file (because
you have old config file, for example), a default value is used. The
default is specified as a string literal and its pointer is assigned to
config->custom_color. The config_free() function calls g_free() on this
pointer uncoditionally but you can't do that on a pointer to string
literal so this causes a segfault.

To avoid that, we can g_strdup() the string literal, just like it is
done for example with config->text_font.
In case "auto_save" is not set in the config file, the error pointer
will point to a GError that is printed by the g_info() but the pointer
is not freed after using. This causes not only memory leak but also a
warning from Glib in case you also do not have "custom_color" in your
config as g_key_file_get_string() will get a pointer that already points
to GError. The warning message looks like this:

(swappy:492252): GLib-WARNING **: 20:11:27.212: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Key file does not have key “custom_color” in group “Default”

A solution is to properly free the error pointer after it is no longer
needed and before it is reused.
@jtheoof jtheoof merged commit 182322d into jtheoof:master Nov 4, 2024
3 checks passed
@jtheoof
Copy link
Owner

jtheoof commented Nov 4, 2024

Thanks, I squashed into 1 commit, this is a fix not a feat. I'm currently without my Linux machine so can't really test the submissions. Thanks for spotting and fixing.

@kadamski
Copy link
Contributor Author

kadamski commented Nov 5, 2024

Sorry, I didn't fully understand your commit message convention. I'm used to the way Linux kernel does it, for example, where we just point to the subsystem the commit is related to. My way of thinking was that this is a fix related to a feat(config). Now I get the convention and it indeed makes more sense.

I can also see I screwed up with my gitconfig filtering on a new system and wrong email address was used for a commit. It was supposed to be my private, not company's email :)

In any case, thank you for merging this so quickly.

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.

2 participants