Skip to content

Commit

Permalink
repo: Fix dir_or_file_path memory leak
Browse files Browse the repository at this point in the history
Coverity points out that we have a memory leak from
`g_strdup(dir_or_file_path)`. We use `g_path_get_dirname()` which
modifies the string in place, to which coverity should understand.
  • Loading branch information
lukewarmtemp committed Jun 19, 2024
1 parent 3ad0c8d commit 973f90b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libostree/ostree-repo-static-delta-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,15 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, GFile
return glnx_throw_errno_prefix (error, "openat(O_DIRECTORY)");
else
{
g_autofree char *dir = dirname (g_strdup (dir_or_file_path));
g_autofree char *dir = "";
if (dir_or_file_path[strlen (dir_or_file_path) - 1] == G_DIR_SEPARATOR)
{
g_autofree char *modifed_dir = g_strdup (dir_or_file_path);
modifed_dir[strlen (modifed_dir) - 1] = '\0';
dir = g_path_get_dirname (modifed_dir);
}
else
dir = g_path_get_dirname (dir_or_file_path);
basename = g_path_get_basename (dir_or_file_path);

if (!glnx_opendirat (AT_FDCWD, dir, TRUE, &dfd, error))
Expand Down

0 comments on commit 973f90b

Please sign in to comment.