Skip to content

Commit

Permalink
sysroot: Make devpath more clear
Browse files Browse the repository at this point in the history
Coverity points out that we have a memory leak from g_strdup(devpath).
This is a mistake from coverity. However, we use `g_path_get_dirname()`
which makes the process clearer since it does not modify the string in
place.
  • Loading branch information
lukewarmtemp committed Jun 19, 2024
1 parent 973f90b commit 01e7d81
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,10 +2240,19 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, OstreeDeployment *deploym
g_autofree char *devpath
= unlocked_state == OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT
? _ostree_sysroot_get_runstate_path (
deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT)
deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT)
: _ostree_sysroot_get_runstate_path (
deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_TRANSIENT);
g_autofree char *devpath_parent = dirname (g_strdup (devpath));
deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_TRANSIENT);

g_autofree char *devpath_parent = "";
if (devpath[strlen (devpath) - 1] == G_DIR_SEPARATOR)
{
g_autofree char *modifed_devpath = g_strdup (devpath);
modifed_devpath[strlen (modifed_devpath) - 1] = '\0';
devpath_parent = g_path_get_dirname (modifed_devpath);
}
else
devpath_parent = g_path_get_dirname (devpath);

if (!glnx_shutil_mkdir_p_at (AT_FDCWD, devpath_parent, 0755, cancellable, error))
return FALSE;
Expand Down

0 comments on commit 01e7d81

Please sign in to comment.