mirror of
https://github.com/systemd/systemd.git
synced 2026-08-05 07:30:30 +00:00
alloc-util: use malloc_usable_size() to determine allocated size
It's a glibc-specific API, but supported on FreeBSD and musl too at least, hence fairly common. This way we can reduce our calls to realloc() as much as possible.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -64,7 +65,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
|
||||
return NULL;
|
||||
|
||||
*p = q;
|
||||
*allocated = newalloc;
|
||||
*allocated = _unlikely_(size == 0) ? newalloc : malloc_usable_size(q) / size;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user