Skip to content

Commit

Permalink
Fix image opening on unix
Browse files Browse the repository at this point in the history
In imgInit() of sqUnixMain.c
- preserve fd instead of throwing it away
- use fileno() to get the file descriptor (fd) created by fopen() instead of
  opening the file again with open() (which leaked a file descriptor due to
  lack of close())
- pass the file descriptor fd instead of the FILE* f to the recently changed
  methods expecting a file descriptor, e.g. readImageFromFileHeapSizeStartingAt()
  • Loading branch information
smalltalking committed Oct 19, 2020
1 parent aafb394 commit 10cb9a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions platforms/unix/vm/sqUnixMain.c
Expand Up @@ -1977,13 +1977,13 @@ void imgInit(void)
dpy->winImageNotFound();
imageNotFound(shortImageName);
}
{
int fd= open(imageName, O_RDONLY);

int fd = fileno(f);
if (fd < 0) abort();
# ifdef DEBUG_IMAGE
printf("fstat(%d) => %d\n", fd, fstat(fd, &sb));
# endif
}

recordFullPathForImageName(shortImageName); /* full image path */
if (extraMemory)
useMmap= 0;
Expand All @@ -1993,12 +1993,12 @@ void imgInit(void)
printf("image size %ld + heap size %ld (useMmap = %d)\n", (long)sb.st_size, extraMemory, useMmap);
# endif
#if SPURVM
readImageFromFileHeapSizeStartingAt(f, 0, 0);
readImageFromFileHeapSizeStartingAt(fd, 0, 0);
#else
extraMemory += (long)sb.st_size;
readImageFromFileHeapSizeStartingAt(f, extraMemory, 0);
readImageFromFileHeapSizeStartingAt(fd, extraMemory, 0);
#endif
sqImageFileClose(f);
sqImageFileClose(fd);
break;
}
}
Expand Down

0 comments on commit 10cb9a7

Please sign in to comment.