Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions dbus/jackdbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ pathname_cat(const char *pathname_a, const char *pathname_b)
bool
paths_init()
{
const char *home_dir, *xdg_config_home, *xdg_log_home;
const char *home_dir, *xdg_config_home, *xdg_state_home;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs are the wrong indentation style here. The whole file contains just a handful of tab-indented lines (which have been like that since 2008), all the rest is indented with 4 spaces. Now would be a good time to not replicate the exact original indentation for the changed lines, but instead to fix all of it. Please use 4 spaces for your changes,, and also fix the remaining old tab-indented lines in the function, there's like 5 of them.


home_dir = getenv("HOME");
if (home_dir == NULL)
Expand All @@ -709,17 +709,21 @@ paths_init()
if (!(xdg_config_home = pathname_cat(home_dir, DEFAULT_XDG_CONFIG))) goto fail;
}

if (!(xdg_log_home = pathname_cat(home_dir, DEFAULT_XDG_LOG))) goto fail;
xdg_state_home = getenv("XDG_STATE_HOME");
if (xdg_state_home == NULL)
{
if (!(xdg_state_home = pathname_cat(home_dir, DEFAULT_XDG_STATE))) goto fail;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This leaks memory and is problematic in general. A pointer from getenv() shouldn't be free() d, but pathname_cat() returns an allocated buffer pointer which definitely should. If you use a single pointer variable like this, you lose information about whether you need to call free() on it before returning.

That being said, none of the temporary allocations from pathname_cat() are ever freed. The whole thing seems to have been leaky since 2008.

}

if (!(g_jackdbus_config_dir = pathname_cat(xdg_config_home, JACKDBUS_DIR))) goto fail;
if (!(g_jackdbus_log_dir = pathname_cat(xdg_log_home, JACKDBUS_DIR))) goto fail;
if (!(g_jackdbus_log_dir = pathname_cat(xdg_state_home, JACKDBUS_DIR))) goto fail;

if (!ensure_dir_exist(xdg_config_home, 0700))
{
goto fail;
}

if (!ensure_dir_exist(xdg_log_home, 0700))
if (!ensure_dir_exist(xdg_state_home, 0700))
{
goto fail;
}
Expand Down
2 changes: 1 addition & 1 deletion dbus/jackdbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//#define DISABLE_SIGNAL_MAGIC

#define DEFAULT_XDG_CONFIG "/.config"
#define DEFAULT_XDG_LOG "/.log"
#define DEFAULT_XDG_STATE "/.local/state"
#define JACKDBUS_DIR "/jack"
#define JACKDBUS_LOG "/jackdbus.log"
#define JACKDBUS_CONF "/conf.xml"
Expand Down