- if (flist->files) {
- new_ptr = realloc_array(flist->files,
- struct file_struct *,
- flist->malloced);
- } else {
- new_ptr = new_array(struct file_struct *,
- flist->malloced);
- }
+ if (flist->malloced < FLIST_START)
+ flist->malloced = FLIST_START;
+ else if (flist->malloced >= FLIST_LINEAR)
+ flist->malloced += FLIST_LINEAR;
+ else
+ flist->malloced *= 2;
+
+ /*
+ * In case count jumped or we are starting the list
+ * with a known size just set it.
+ */
+ if (flist->malloced < flist->count)
+ flist->malloced = flist->count;
+
+ if (flist->files) {
+ new_ptr = realloc_array(flist->files,
+ struct file_struct *, flist->malloced);
+ } else {
+ new_ptr = new_array(struct file_struct *, flist->malloced);
+ }