projects
/
systemd
/
.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
23964f7
)
alloc-util: use malloc_usable_size() to determine allocated size
author
Lennart Poettering
<lennart@poettering.net>
Wed, 20 Mar 2019 09:31:38 +0000
(10:31 +0100)
committer
Lennart Poettering
<lennart@poettering.net>
Wed, 20 Mar 2019 09:48:33 +0000
(10:48 +0100)
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.
src/basic/alloc-util.c
patch
|
blob
|
history
diff --git
a/src/basic/alloc-util.c
b/src/basic/alloc-util.c
index f4bd33f4e014246a9c9e68f8f75e0023541a967d..1e4ee722f204c4748ae916aa485f8e102c245570 100644
(file)
--- a/
src/basic/alloc-util.c
+++ b/
src/basic/alloc-util.c
@@
-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;
}