Skip to content

Commit c2387cf

Browse files
committed
bin/xbps-query: fix more memory leaks in --search
1 parent 461bff5 commit c2387cf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

bin/xbps-query/search.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pattern, bool regex)
174174

175175
ctx.results = xbps_array_create();
176176
if (!ctx.results) {
177-
xbps_error_oom();
178-
return EXIT_FAILURE;
177+
r = xbps_error_oom();
178+
goto err;
179179
}
180180

181181
if (ctx.maxcols > 0) {
182182
ctx.linebuf = malloc(ctx.maxcols);
183183
if (!ctx.linebuf) {
184-
xbps_error_oom();
185-
return EXIT_FAILURE;
184+
r = xbps_error_oom();
185+
goto err;
186186
}
187187
}
188188

@@ -191,14 +191,17 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pattern, bool regex)
191191
else
192192
r = xbps_pkgdb_foreach_cb(xhp, search_cb, &ctx);
193193
if (r != 0)
194-
return EXIT_FAILURE;
194+
goto err;
195195

196196
print_results(xhp, &ctx);
197197

198-
xbps_object_release(ctx.results);
198+
err:
199+
if (ctx.results)
200+
xbps_object_release(ctx.results);
199201
if (regex)
200202
regfree(&ctx.regexp);
201-
return 0;
203+
free(ctx.linebuf);
204+
return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
202205
}
203206

204207
struct search_prop_ctx {

0 commit comments

Comments
 (0)