Skip to content

Commit

Permalink
Fix bug where not failing if out of memory
Browse files Browse the repository at this point in the history
Still failing multi-oom.
Also fails syn-read and exec-missing on bochs.
  • Loading branch information
omegaphoenix committed Feb 20, 2017
1 parent 488003b commit cd645c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/threads/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ int next_fd(struct thread *cur) {
int add_open_file(struct thread *cur, struct file *file, int fd) {
/* Initialize file */
struct sys_file *new_file = palloc_get_page(PAL_ZERO);
/* Not enough memory. */
if (new_file == NULL) {
return -1;
}
memset(new_file, 0, sizeof *new_file);
new_file->file = file;
new_file->fd = fd;
Expand Down
6 changes: 5 additions & 1 deletion src/userprog/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ int sys_open(const char *file) {
fd = add_open_file(cur, open_file, fd);
release_file_lock();

ASSERT(fd > 1); /* Only for stdin and stdout */
if (fd == -1) {
acquire_file_lock();
file_close(open_file);
release_file_lock();
}
return fd;
}

Expand Down

0 comments on commit cd645c0

Please sign in to comment.