Skip to content

Commit e1bc9a0

Browse files
committed
bin/xbps-create: fix memory leak in alternatives processing
1 parent f9bd8a5 commit e1bc9a0

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

bin/xbps-create/main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,19 @@ process_one_alternative(const char *altgrname, const char *val)
236236
xbps_dictionary_t d;
237237
xbps_array_t a;
238238
const char *altfiles;
239-
bool alloc = false;
239+
bool alloc_dict = false, alloc_array = false;
240240

241241
if ((d = xbps_dictionary_get(pkg_propsd, "alternatives")) == NULL) {
242242
d = xbps_dictionary_create();
243243
if (d == NULL)
244244
die("xbps_dictionary_create");
245-
alloc = true;
245+
alloc_dict = true;
246246
}
247247
if ((a = xbps_dictionary_get(d, altgrname)) == NULL) {
248248
a = xbps_array_create();
249249
if (a == NULL)
250250
die("xbps_array_create");
251+
alloc_array = true;
251252
}
252253
altfiles = strchr(val, ':') + 1;
253254
assert(altfiles);
@@ -256,10 +257,10 @@ process_one_alternative(const char *altgrname, const char *val)
256257
xbps_dictionary_set(d, altgrname, a);
257258
xbps_dictionary_set(pkg_propsd, "alternatives", d);
258259

259-
if (alloc) {
260+
if (alloc_array)
260261
xbps_object_release(a);
262+
if (alloc_dict)
261263
xbps_object_release(d);
262-
}
263264
}
264265

265266

0 commit comments

Comments
 (0)