mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
Switch to a self-starting allocation scheme.
This commit is contained in:
parent
e19e6098b3
commit
5a51c23be3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90268
|
@ -359,25 +359,18 @@ _fetch_add_entry(struct url_ent **p, int *size, int *len,
|
|||
struct url_ent *tmp;
|
||||
|
||||
if (*p == NULL) {
|
||||
#define INITIAL_SIZE 8
|
||||
if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
_fetch_syserr();
|
||||
return (-1);
|
||||
}
|
||||
*size = INITIAL_SIZE;
|
||||
*size = 0;
|
||||
*len = 0;
|
||||
#undef INITIAL_SIZE
|
||||
}
|
||||
|
||||
if (*len >= *size - 1) {
|
||||
tmp = realloc(*p, *size * 2 * sizeof **p);
|
||||
tmp = realloc(*p, (*size * 2 + 1) * sizeof **p);
|
||||
if (tmp == NULL) {
|
||||
errno = ENOMEM;
|
||||
_fetch_syserr();
|
||||
return (-1);
|
||||
}
|
||||
*size *= 2;
|
||||
*size = (*size * 2 + 1);
|
||||
*p = tmp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue