Skip to content

Commit d5a5630

Browse files
committed
bin/xbps-rindex: fix memory leak in error path
1 parent 66b33f6 commit d5a5630

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

bin/xbps-rindex/remove-obsoletes.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "defs.h"
4242
#include "xbps/xbps_dictionary.h"
4343
#include "xbps/xbps_object.h"
44-
#include "xbps_api_impl.h"
4544

4645
static int
4746
remove_pkg(const char *repodir, const char *file)
@@ -163,13 +162,16 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
163162
if ((dirp = opendir(".")) == NULL) {
164163
xbps_error_printf("xbps-rindex: failed to open %s: %s\n",
165164
repodir, strerror(errno));
166-
goto err;
165+
xbps_repo_release(repo);
166+
return EXIT_FAILURE;
167167
}
168168

169169
array = xbps_array_create();
170170
if (!array) {
171171
xbps_error_printf("failed to allocate array: %s\n", strerror(-errno));
172-
goto err;
172+
xbps_repo_release(repo);
173+
closedir(dirp);
174+
return EXIT_FAILURE;
173175
}
174176

175177
suffixlen = snprintf(suffix, sizeof(suffix), ".%s.xbps",
@@ -199,13 +201,15 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
199201
closedir(dirp);
200202

201203
r = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, repo);
202-
if (r < 0)
203-
goto err;
204204

205205
xbps_repo_release(repo);
206206
xbps_object_release(array);
207+
208+
if (r < 0)
209+
return EXIT_FAILURE;
207210
return EXIT_SUCCESS;
208211
err:
212+
closedir(dirp);
209213
xbps_repo_release(repo);
210214
xbps_object_release(array);
211215
return EXIT_FAILURE;

0 commit comments

Comments
 (0)