From a9d526836e1160b2233bf26a2d1dd6584dec5dd4 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Fri, 17 Feb 2012 10:02:44 +0200 Subject: apk: fix some unharmful leaks reported by valgrind --- src/apk.c | 26 +++++++++++++++++--------- src/database.c | 1 + src/solver.c | 1 + 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/apk.c b/src/apk.c index ccab27e..4fce15b 100644 --- a/src/apk.c +++ b/src/apk.c @@ -316,8 +316,8 @@ int main(int argc, char **argv) case 0: break; case 'h': - return usage(applet); - break; + r = usage(applet); + goto err; case 'p': dbopts.root = optarg; break; @@ -339,7 +339,8 @@ int main(int argc, char **argv) apk_verbosity++; break; case 'V': - return version(); + r = version(); + goto err; case 'f': apk_flags |= APK_FORCE; break; @@ -383,14 +384,18 @@ int main(int argc, char **argv) if (applet == NULL || applet->parse == NULL || applet->parse(ctx, &dbopts, r, optindex - ARRAY_SIZE(generic_options), - optarg) != 0) - return usage(applet); + optarg) != 0) { + r = usage(applet); + goto err; + } break; } } - if (applet == NULL) - return usage(NULL); + if (applet == NULL) { + r = usage(NULL); + goto err; + } argc -= optind; argv += optind; @@ -403,13 +408,16 @@ int main(int argc, char **argv) if (r != 0) { apk_error("Failed to open apk database: %s", apk_error_str(r)); - return r; + goto err; } r = applet->main(ctx, &db, argc, argv); apk_db_close(&db); if (r == -EINVAL) - return usage(applet); + r = usage(applet); +err: + if (ctx) + free(ctx); return r; } diff --git a/src/database.c b/src/database.c index 11f705d..e6945c3 100644 --- a/src/database.c +++ b/src/database.c @@ -1508,6 +1508,7 @@ void apk_db_close(struct apk_database *db) for (i = 0; i < db->num_repos; i++) { free(db->repos[i].url); + free(db->repos[i].description.ptr); } for (i = 0; i < db->protected_paths->num; i++) free(db->protected_paths->item[i]); diff --git a/src/solver.c b/src/solver.c index 7d5a5b3..0283791 100644 --- a/src/solver.c +++ b/src/solver.c @@ -1630,6 +1630,7 @@ int apk_solver_commit(struct apk_database *db, apk_solver_print_errors(db, solution, world, r); } apk_solution_array_free(&solution); + apk_change_array_free(&changeset.changes); return r; } -- cgit v1.2.3-70-g09d2