Skip to content

Commit 5e88e9c

Browse files
committed
lib: fix memory leak in conflict string generation
1 parent 5ddcae7 commit 5e88e9c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/transaction_check_conflicts.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
101101
buf = xbps_xasprintf("CONFLICT: %s with "
102102
"installed pkg %s (matched by %s)",
103103
repopkgver, pkgver, cfpkg);
104-
if (!xbps_array_add_cstring(trans_cflicts, buf))
104+
if (!buf)
105+
return xbps_error_oom();
106+
if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf)) {
107+
free(buf);
105108
return xbps_error_oom();
109+
}
106110
continue;
107111
}
108112
/*
@@ -129,8 +133,10 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
129133
repopkgver, pkgver, cfpkg);
130134
if (!buf)
131135
return xbps_error_oom();
132-
if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf))
136+
if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf)) {
137+
free(buf);
133138
return xbps_error_oom();
139+
}
134140
continue;
135141
}
136142
}
@@ -192,8 +198,10 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
192198
repopkgver, pkgver, cfpkg);
193199
if (!buf)
194200
return xbps_error_oom();
195-
if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf))
201+
if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf)) {
202+
free(buf);
196203
return xbps_error_oom();
204+
}
197205
continue;
198206
}
199207
}

0 commit comments

Comments
 (0)