repo: Fix `dir_or_file_path` memory leak
authorLuke Yang <luke.jia.yang@gmail.com>
Wed, 12 Jun 2024 19:55:37 +0000 (15:55 -0400)
committerLuke Yang <luke.jia.yang@gmail.com>
Thu, 20 Jun 2024 19:09:11 +0000 (15:09 -0400)
Coverity points out that we have a memory leak from
`g_strdup(dir_or_file_path)`. Make the duplication of the string a
temporary variable that is freed using `g_autofree`.

src/libostree/ostree-repo-static-delta-core.c

index dc57a2f03d66df392f731b095213e88303eda6be..1a1b3309522693703a576da2e0628204429a4359 100644 (file)
@@ -409,7 +409,8 @@ 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 *tmpbuf = g_strdup (dir_or_file_path);
+          const char *dir = dirname (tmpbuf);
           basename = g_path_get_basename (dir_or_file_path);
 
           if (!glnx_opendirat (AT_FDCWD, dir, TRUE, &dfd, error))