Skip to content

Commit

Permalink
Use g_autofree where possible
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Fabik <mfabik@redhat.com>
  • Loading branch information
michalfabik authored and mgrabovsky committed Jun 17, 2020
1 parent a753b10 commit 89e0ddd
Show file tree
Hide file tree
Showing 40 changed files with 172 additions and 386 deletions.
3 changes: 1 addition & 2 deletions src/applet/test_report.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char** argv)
problem_data_free(problem_data);
if (!dd)
return 1;
char *dir_name = strdup(dd->dd_dirname);
g_autofree char *dir_name = strdup(dd->dd_dirname);
dd_close(dd);

printf("Temp dump dir: '%s'\n", dir_name);
Expand All @@ -56,7 +56,6 @@ int main(int argc, char** argv)
free_run_event_state(run_state);

// delete_dump_dir(dir_name);
free(dir_name);

return 0;
}
13 changes: 4 additions & 9 deletions src/configuration-gui/abrt-config-widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,15 @@ abrt_config_widget_init(AbrtConfigWidget *self)
gpp_app = "gnome-privacy-panel.desktop";

GDesktopAppInfo *app = g_desktop_app_info_new(gpp_app);
char *message = NULL;
char *markup = NULL;
g_autofree char *message = NULL;
g_autofree char *markup = NULL;
if (!app)
{
/* Make the switch editable */
self->priv->options[ABRT_OPT_SEND_UREPORT].config = self->priv->privacy_gsettings;

char *os_release = libreport_xmalloc_open_read_close("/etc/os-release", /*no size limit*/NULL);
char *privacy_policy = NULL;
g_autofree char *os_release = libreport_xmalloc_open_read_close("/etc/os-release", /*no size limit*/NULL);
g_autofree char *privacy_policy = NULL;

/* Try to get the value of PRIVACY_POLICY from /etc/os-release */
sr_parse_os_release(os_release, os_release_callback, (void *)&privacy_policy);
Expand All @@ -486,8 +486,6 @@ abrt_config_widget_init(AbrtConfigWidget *self)
else
markup = g_strdup_printf("<i>%s</i>", message);

free(privacy_policy);
free(os_release);
}
else
{
Expand Down Expand Up @@ -530,9 +528,6 @@ abrt_config_widget_init(AbrtConfigWidget *self)
/* Let users to copy the warning. */
gtk_label_set_selectable(GTK_LABEL(lbl), TRUE);

free(markup);
free(message);

gtk_box_pack_start(GTK_BOX(hbox_auto_reporting), lbl, false, false, 0);
}

Expand Down
17 changes: 5 additions & 12 deletions src/daemon/abrt-action-save-container-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ void dump_docker_info(struct dump_dir *dd, const char *root_dir)
dd_save_text(dd, FILENAME_CONTAINER, "docker");

json_object *json = NULL;
char *mntnf_path = g_build_filename(dd->dd_dirname ? dd->dd_dirname : "", FILENAME_MOUNTINFO, NULL);
g_autofree char *mntnf_path = g_build_filename(dd->dd_dirname ? dd->dd_dirname : "", FILENAME_MOUNTINFO, NULL);
FILE *mntnf_file = fopen(mntnf_path, "r");
free(mntnf_path);

struct mount_point {
const char *name;
Expand All @@ -41,7 +40,7 @@ void dump_docker_info(struct dump_dir *dd, const char *root_dir)
};

char *container_id = NULL;
char *output = NULL;
g_autofree char *output = NULL;

/* initialized to 0 because we call libreport_mountinfo_destroy below */
struct mountinfo mntnf = {0};
Expand Down Expand Up @@ -101,7 +100,7 @@ void dump_docker_info(struct dump_dir *dd, const char *root_dir)
continue;
}

char *docker_inspect_cmdline = NULL;
g_autofree char *docker_inspect_cmdline = NULL;
if (root_dir != NULL)
docker_inspect_cmdline = g_strdup_printf("chroot %s /bin/sh -c \"docker inspect %s\"", root_dir, container_id);
else
Expand All @@ -110,16 +109,13 @@ void dump_docker_info(struct dump_dir *dd, const char *root_dir)
log_debug("Executing: '%s'", docker_inspect_cmdline);
output = libreport_run_in_shell_and_save_output(0, docker_inspect_cmdline, "/", NULL);

free(docker_inspect_cmdline);

if (output == NULL || strcmp(output, "[]\n") == 0)
{
log_debug("Unsupported container ID: '%s'", container_id);

free(container_id);
container_id = NULL;

free(output);
output = NULL;

continue;
Expand All @@ -139,7 +135,6 @@ void dump_docker_info(struct dump_dir *dd, const char *root_dir)
dd_save_text(dd, FILENAME_DOCKER_INSPECT, output);

json = json_tokener_parse(output);
free(output);

if (json == NULL)
{
Expand Down Expand Up @@ -186,9 +181,8 @@ void dump_lxc_info(struct dump_dir *dd, const char *lxc_cmd)
if (!dd_exist(dd, FILENAME_CONTAINER))
dd_save_text(dd, FILENAME_CONTAINER, "lxc");

char *mntnf_path = g_build_filename(dd->dd_dirname ? dd->dd_dirname : "", FILENAME_MOUNTINFO, NULL);
g_autofree char *mntnf_path = g_build_filename(dd->dd_dirname ? dd->dd_dirname : "", FILENAME_MOUNTINFO, NULL);
FILE *mntnf_file = fopen(mntnf_path, "r");
free(mntnf_path);

struct mountinfo mntnf;
int r = libreport_get_mountinfo_for_mount_point(mntnf_file, &mntnf, "/");
Expand Down Expand Up @@ -274,7 +268,7 @@ int main(int argc, char **argv)
if (dd == NULL)
libreport_xfunc_die();

char *container_cmdline = dd_load_text_ext(dd, FILENAME_CONTAINER_CMDLINE, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE);
g_autofree char *container_cmdline = dd_load_text_ext(dd, FILENAME_CONTAINER_CMDLINE, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE);
if (container_cmdline == NULL)
error_msg_and_die("The crash didn't occur in container");

Expand All @@ -285,7 +279,6 @@ int main(int argc, char **argv)
else
error_msg_and_die("Unsupported container technology");

free(container_cmdline);
dd_close(dd);

return 0;
Expand Down
21 changes: 7 additions & 14 deletions src/daemon/abrt-action-save-package-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,16 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name, const ch
if (!dd)
return 1;

char *type = dd_load_text(dd, FILENAME_TYPE);
g_autofree char *type = dd_load_text(dd, FILENAME_TYPE);
bool kernel_oops = !strcmp(type, "Kerneloops") || !strcmp(type, "vmcore");
free(type);

char *cmdline = NULL;
char *executable = NULL;
char *rootdir = NULL;
char *package_short_name = NULL;
char *fingerprint = NULL;
g_autofree char *cmdline = NULL;
g_autofree char *executable = NULL;
g_autofree char *rootdir = NULL;
g_autofree char *package_short_name = NULL;
g_autofree char *fingerprint = NULL;
struct pkg_nevra *pkg_name = NULL;
char *component = NULL;
g_autofree char *component = NULL;
char *kernel = NULL;
int error = 1;
/* note: "goto ret" statements below free all the above variables,
Expand Down Expand Up @@ -457,13 +456,7 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name, const ch
if (dd)
dd_close(dd);

free(cmdline);
free(executable);
free(rootdir);
free(package_short_name);
free_pkg_nevra(pkg_name);
free(component);
free(fingerprint);

return error;
}
Expand Down
4 changes: 1 addition & 3 deletions src/daemon/abrt-auto-reporting.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int main(int argc, char *argv[])

if ((opts & OPT_u))
{
char *tmp_password = NULL;
g_autofree char *tmp_password = NULL;
if (!(opts & OPT_p))
{
password = tmp_password = libreport_ask_password(_("Password:"));
Expand All @@ -353,8 +353,6 @@ int main(int argc, char *argv[])
libreport_save_plugin_conf_file(UREPORT_NAME, ureport_conf_bck);
goto finito;
}

free(tmp_password);
}

if ((opts & OPT_c))
Expand Down
16 changes: 5 additions & 11 deletions src/daemon/abrt-handle-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static int is_crash_a_dup(const char *dump_dir_name, void *param)
type = dd_load_text(dd, FILENAME_TYPE);
free(executable);
executable = dd_load_text_ext(dd, FILENAME_EXECUTABLE, DD_FAIL_QUIETLY_ENOENT);
char *container_id = dd_load_text_ext(dd, FILENAME_CONTAINER_ID, DD_FAIL_QUIETLY_ENOENT);
g_autofree char *container_id = dd_load_text_ext(dd, FILENAME_CONTAINER_ID, DD_FAIL_QUIETLY_ENOENT);
dup_uuid_init(dd);
dup_corebt_init(dd);
dd_close(dd);
Expand All @@ -256,7 +256,7 @@ static int is_crash_a_dup(const char *dump_dir_name, void *param)

char *tmp_concat_path = g_build_filename(abrt_g_settings_dump_location, dent->d_name, NULL);

char *dump_dir_name2 = realpath(tmp_concat_path, NULL);
g_autofree char *dump_dir_name2 = realpath(tmp_concat_path, NULL);
if (libreport_g_verbose > 1 && !dump_dir_name2)
perror_msg("realpath(%s)", tmp_concat_path);

Expand All @@ -265,8 +265,8 @@ static int is_crash_a_dup(const char *dump_dir_name, void *param)
if (!dump_dir_name2)
continue;

char *dd_uid = NULL, *dd_type = NULL;
char *dd_executable = NULL, *dd_container_id = NULL;
g_autofree char *dd_uid = NULL, *dd_type = NULL;
g_autofree char *dd_executable = NULL, *dd_container_id = NULL;

if (strcmp(dump_dir_name, dump_dir_name2) == 0)
goto next; /* we are never a dup of ourself */
Expand Down Expand Up @@ -323,17 +323,12 @@ static int is_crash_a_dup(const char *dump_dir_name, void *param)
}

next:
free(dump_dir_name2);
dd_close(dd);
free(dd_uid);
free(dd_type);
free(dd_container_id);
}
closedir(dir);

end:
free((char*)dump_dir_name);
free(container_id);
return retval;
}

Expand Down Expand Up @@ -402,7 +397,7 @@ int main(int argc, char **argv)
}

bool post_create = (strcmp(event_name, "post-create") == 0);
char *dump_dir_name = NULL;
g_autofree char *dump_dir_name = NULL;
while (*argv)
{
dump_dir_name = g_strdup(*argv++);
Expand Down Expand Up @@ -458,7 +453,6 @@ int main(int argc, char **argv)
if (r != 0)
return r; /* yes */

free(dump_dir_name);
dump_dir_name = NULL;
}

Expand Down
4 changes: 1 addition & 3 deletions src/daemon/abrt-inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
* and we were going out of sync wrt struct inotify_event's layout.
*/
inotify_bytes += 2 * (sizeof(struct inotify_event) + FILENAME_MAX);
char *buf = g_malloc(inotify_bytes);
g_autofree char *buf = g_malloc(inotify_bytes);
errno = 0;
gsize len;
GError *gerror = NULL;
Expand All @@ -73,7 +73,6 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
if (err != G_IO_STATUS_NORMAL)
{
error_msg("Error reading inotify fd: %s", gerror ? gerror->message : "unknown");
free(buf);
if (gerror)
g_error_free(gerror);
return FALSE; /* "remove this event" (huh??) */
Expand All @@ -96,7 +95,6 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin

aic->handler(aic, event, aic->user_data);
}
free(buf);
return TRUE;
}

Expand Down
Loading

0 comments on commit 89e0ddd

Please sign in to comment.