diff options
| -rw-r--r-- | fs/file.c | 10 |
1 files changed, 8 insertions, 2 deletions
| @@ -308,11 +308,16 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp) | |||
| 308 | 308 | ||
| 309 | /* | 309 | /* |
| 310 | * Check whether we need to allocate a larger fd array and fd set. | 310 | * Check whether we need to allocate a larger fd array and fd set. |
| 311 | * Note: we're not a clone task, so the open count won't change. | ||
| 312 | */ | 311 | */ |
| 313 | if (open_files > new_fdt->max_fds) { | 312 | while (unlikely(open_files > new_fdt->max_fds)) { |
| 314 | spin_unlock(&oldf->file_lock); | 313 | spin_unlock(&oldf->file_lock); |
| 315 | 314 | ||
| 315 | if (new_fdt != &newf->fdtab) { | ||
| 316 | free_fdarr(new_fdt); | ||
| 317 | free_fdset(new_fdt); | ||
| 318 | kfree(new_fdt); | ||
| 319 | } | ||
| 320 | |||
| 316 | new_fdt = alloc_fdtable(open_files - 1); | 321 | new_fdt = alloc_fdtable(open_files - 1); |
| 317 | if (!new_fdt) { | 322 | if (!new_fdt) { |
| 318 | *errorp = -ENOMEM; | 323 | *errorp = -ENOMEM; |
| @@ -335,6 +340,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp) | |||
| 335 | */ | 340 | */ |
| 336 | spin_lock(&oldf->file_lock); | 341 | spin_lock(&oldf->file_lock); |
| 337 | old_fdt = files_fdtable(oldf); | 342 | old_fdt = files_fdtable(oldf); |
| 343 | open_files = count_open_files(old_fdt); | ||
| 338 | } | 344 | } |
| 339 | 345 | ||
| 340 | old_fds = old_fdt->fd; | 346 | old_fds = old_fdt->fd; |
