Skip to content
Snippets Groups Projects
Commit 2733a959 authored by Pekka Paalanen's avatar Pekka Paalanen
Browse files

libweston: refactor update_lowest_free_bucket()


No functional change here other than asserting that next_num didn't wrap
around. This reorganization helps adding the code
needed to clear the memory added by xrealloc() in the next patch.

Signed-off-by: default avatarPekka Paalanen <pekka.paalanen@collabora.com>
parent 1b765563
No related branches found
No related tags found
1 merge request!1699Fix realloc in weston_idalloc
...@@ -87,6 +87,7 @@ update_lowest_free_bucket(struct weston_idalloc *idalloc) ...@@ -87,6 +87,7 @@ update_lowest_free_bucket(struct weston_idalloc *idalloc)
{ {
uint32_t old_lowest_free_bucket = idalloc->lowest_free_bucket; uint32_t old_lowest_free_bucket = idalloc->lowest_free_bucket;
uint32_t *bucket; uint32_t *bucket;
uint32_t next_num;
unsigned int i; unsigned int i;
for (i = old_lowest_free_bucket; i < idalloc->num_buckets; i++) { for (i = old_lowest_free_bucket; i < idalloc->num_buckets; i++) {
...@@ -100,12 +101,16 @@ update_lowest_free_bucket(struct weston_idalloc *idalloc) ...@@ -100,12 +101,16 @@ update_lowest_free_bucket(struct weston_idalloc *idalloc)
return; return;
} }
/* We didn't find any free bucket, so we need to add more buckets. The /* We didn't find any free bucket, so we need to add more buckets. */
* first one (from the new added) will be the lowest free. */ next_num = idalloc->num_buckets * 2;
weston_assert_uint32_gt(idalloc->compositor, next_num, idalloc->num_buckets);
idalloc->buckets = xrealloc(idalloc->buckets, next_num * sizeof(*idalloc->buckets));
/* The first one (from the new added) is the lowest free. */
idalloc->lowest_free_bucket = idalloc->num_buckets; idalloc->lowest_free_bucket = idalloc->num_buckets;
idalloc->num_buckets *= 2;
idalloc->buckets = xrealloc(idalloc->buckets, idalloc->num_buckets = next_num;
idalloc->num_buckets * sizeof(*idalloc->buckets));
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment