Skip to content

Commit

Permalink
Use already implemented clear for COMPS_HSList (RhBug:1888343)
Browse files Browse the repository at this point in the history
Instead of reimplementing clear for COMPS_HSList use comps_hslist_clear.
The crash was caused by dangling pointers first and last in the
COMPS_HSList (rt->subnodes) struct, function comps_hslist_clear clears
them out properly.

= changelog =
msg: Fix a crash when clearing COMPS_ObjRTree
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1888343
  • Loading branch information
kontura authored and Conan-Kudo committed Oct 22, 2020
1 parent 34abc4e commit 76bc005
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 2 additions & 13 deletions libcomps/src/comps_objradix.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,20 +611,9 @@ void comps_objrtree_unset(COMPS_ObjRTree * rt, const char * key) {
}

void comps_objrtree_clear(COMPS_ObjRTree * rt) {
COMPS_HSListItem *it, *oldit;
if (rt==NULL) return;
if (rt->subnodes == NULL) return;
oldit = rt->subnodes->first;
it = (oldit)?oldit->next:NULL;
for (;it != NULL; it=it->next) {
comps_object_destroy(oldit->data);
free(oldit);
oldit = it;
}
if (oldit) {
comps_object_destroy(oldit->data);
free(oldit);
}
comps_hslist_clear(rt->subnodes);
rt->len = 0;
}

inline COMPS_HSList* __comps_objrtree_all(COMPS_ObjRTree * rt, char keyvalpair) {
Expand Down
10 changes: 10 additions & 0 deletions libcomps/src/python/tests/__test.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,16 @@ def test_envs(self):

_f([x.name for x in env.option_ids], option_ids)

#@unittest.skip("")
def test_clear_for_COMPS_ObjRTree_such_as_group_or_category_namy_by_lang(self):
comps = libcomps.Comps()
ret = comps.fromxml_f("comps/f21-rawhide-comps.xml")

env = comps.categories[0].name_by_lang.clear()
env = comps.groups[0].name_by_lang.clear()

self.assertEqual(str(comps.categories[0].name_by_lang), u'{}')
self.assertEqual(str(comps.groups[0].name_by_lang), u'{}')

#@unittest.skip("")
def test_xml_options(self):
Expand Down

0 comments on commit 76bc005

Please sign in to comment.