Skip to content

Commit

Permalink
Fix memory leaks
Browse files Browse the repository at this point in the history
Found by building a package while built with libasan

Signed-off-by: Hubert Figuière <hub@figuiere.net>
  • Loading branch information
hfiguiere authored and TingPing committed Feb 22, 2024
1 parent 64e9800 commit 2ee5139
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/builder-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ builder_context_finalize (GObject *object)
g_clear_object (&self->checksums_dir);
g_clear_object (&self->rofiles_dir);
g_clear_object (&self->ccache_dir);
g_clear_object (&self->rofiles_allocated_dir);
g_clear_object (&self->app_dir);
g_clear_object (&self->run_dir);
g_clear_object (&self->base_dir);
Expand Down Expand Up @@ -1087,7 +1088,7 @@ builder_context_set_enable_ccache (BuilderContext *self,

for (i = 0; i < G_N_ELEMENTS (compilers); i++)
{
const char *symlink_path = g_build_filename (ccache_bin_path, compilers[i], NULL);
g_autofree char *symlink_path = g_build_filename (ccache_bin_path, compilers[i], NULL);
if (symlink ("/usr/bin/ccache", symlink_path) && errno != EEXIST)
{
glnx_set_error_from_errno (error);
Expand Down
2 changes: 1 addition & 1 deletion src/builder-flatpak-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ flatpak_build_file_va (GFile *base,

while ((arg = va_arg (args, const gchar *)))
{
GFile *child = g_file_resolve_relative_path (res, arg);
g_autoptr(GFile) child = g_file_resolve_relative_path (res, arg);
g_set_object (&res, child);
}

Expand Down
4 changes: 3 additions & 1 deletion src/builder-manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,8 @@ builder_manifest_find_appdata_file (BuilderManifest *self,
source = g_file_get_child (appdata_dir, basename);
if (g_file_query_exists (source, NULL))
return g_steal_pointer (&source);

g_clear_object (&source);
}
}
return NULL;
Expand Down Expand Up @@ -2941,7 +2943,7 @@ builder_manifest_cleanup (BuilderManifest *self,
G_KEY_FILE_DESKTOP_GROUP,
"X-Flatpak-RenamedFrom",
NULL, NULL);
const char **new_renames = NULL;
g_autofree const char **new_renames = NULL;
int old_rename_len = 0;
int new_rename_len = 0;

Expand Down
5 changes: 3 additions & 2 deletions src/builder-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,8 @@ setup_build_args (GFile *app_dir,

g_ptr_array_add (args, g_file_get_path (app_dir));

*cwd_file = g_file_new_for_path (source_dir_path_canonical);
if (cwd_file)
*cwd_file = g_file_new_for_path (source_dir_path_canonical);

return g_steal_pointer (&args);
}
Expand Down Expand Up @@ -1350,7 +1351,7 @@ build (GFile *app_dir,
va_end (ap);

args =
setup_build_args (app_dir, module_name, context, source_dir, cwd_subdir, flatpak_opts, env, &cwd_file);
setup_build_args (app_dir, module_name, context, source_dir, cwd_subdir, flatpak_opts, env, NULL);
unresolved_args =
setup_build_args (app_dir, module_name, context, source_dir, cwd_subdir, flatpak_opts, unresolved_env, &cwd_file);

Expand Down
15 changes: 9 additions & 6 deletions src/builder-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ get_all_options (BuilderOptions *self, BuilderContext *context)
return options;
}

static const char *
static char *
builder_options_get_flags (BuilderOptions *self,
BuilderContext *context,
size_t field_offset,
Expand Down Expand Up @@ -913,31 +913,31 @@ get_sdk_flags (BuilderOptions *self, BuilderContext *context, const char *(*meth
return NULL;
}

const char *
char *
builder_options_get_cflags (BuilderOptions *self, BuilderContext *context)
{
return builder_options_get_flags (self, context, G_STRUCT_OFFSET (BuilderOptions, cflags),
G_STRUCT_OFFSET (BuilderOptions, cflags_override),
get_sdk_flags (self, context, builder_sdk_config_get_cflags));
}

const char *
char *
builder_options_get_cxxflags (BuilderOptions *self, BuilderContext *context)
{
return builder_options_get_flags (self, context, G_STRUCT_OFFSET (BuilderOptions, cxxflags),
G_STRUCT_OFFSET (BuilderOptions, cxxflags_override),
get_sdk_flags (self, context, builder_sdk_config_get_cxxflags));
}

const char *
char *
builder_options_get_cppflags (BuilderOptions *self, BuilderContext *context)
{
return builder_options_get_flags (self, context, G_STRUCT_OFFSET (BuilderOptions, cppflags),
G_STRUCT_OFFSET (BuilderOptions, cppflags_override),
get_sdk_flags (self, context, builder_sdk_config_get_cppflags));
}

const char *
char *
builder_options_get_ldflags (BuilderOptions *self, BuilderContext *context)
{
return builder_options_get_flags (self, context, G_STRUCT_OFFSET (BuilderOptions, ldflags),
Expand Down Expand Up @@ -1134,7 +1134,10 @@ builder_options_get_env (BuilderOptions *self, BuilderContext *context)
GList *l;
int i;
char **envp = NULL;
const char *cflags, *cppflags, *cxxflags, *ldflags;
g_autofree char *cflags = NULL;
g_autofree char *cppflags = NULL;
g_autofree char *cxxflags = NULL;
g_autofree char *ldflags = NULL;

envp = builder_context_extend_env_pre (context, envp);

Expand Down
16 changes: 8 additions & 8 deletions src/builder-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ typedef struct BuilderOptions BuilderOptions;

GType builder_options_get_type (void);

const char *builder_options_get_cflags (BuilderOptions *self,
BuilderContext *context);
const char *builder_options_get_cxxflags (BuilderOptions *self,
BuilderContext *context);
const char *builder_options_get_cppflags (BuilderOptions *self,
BuilderContext *context);
const char *builder_options_get_ldflags (BuilderOptions *self,
BuilderContext *context);
char *builder_options_get_cflags (BuilderOptions *self,
BuilderContext *context);
char *builder_options_get_cxxflags (BuilderOptions *self,
BuilderContext *context);
char *builder_options_get_cppflags (BuilderOptions *self,
BuilderContext *context);
char *builder_options_get_ldflags (BuilderOptions *self,
BuilderContext *context);
const char *builder_options_get_prefix (BuilderOptions *self,
BuilderContext *context);
const char *builder_options_get_libdir (BuilderOptions *self,
Expand Down

0 comments on commit 2ee5139

Please sign in to comment.