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

Don't unconditionally free() xdg_data_home_dir #421

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,12 @@ void Sys_Init(void)
}
// Attempt to respect user's XDG_DATA_HOME environment variable
xdg_data_home_dir = getenv("XDG_DATA_HOME");
bool xdg_data_home_dir_allocated = false;
if (!xdg_data_home_dir) {
size_t xdg_unset_len = strlen(homedir) + strlen("/.local/share") + 1;

xdg_data_home_dir = malloc(xdg_unset_len);
xdg_data_home_dir_allocated = true;

if (xdg_data_home_dir == NULL) {
Sys_Error("%s:xdg_data_home_dir: malloc() failed.\n", __func__);
Expand All @@ -274,7 +276,8 @@ void Sys_Init(void)
check_snprintf = snprintf(homegamedir, sizeof(homegamedir),
"%s/%s", xdg_data_home_dir, "quake2rtx");

free(xdg_data_home_dir);
if (xdg_data_home_dir_allocated)
free(xdg_data_home_dir);

if (check_snprintf < 0) {
Sys_Error("%s:homegamedir: snprintf() failed with return "
Expand Down
Loading