diff options
author | Tony Luck <tony.luck@intel.com> | 2020-09-03 15:33:20 -0700 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2020-09-03 15:37:50 -0700 |
commit | a4e0b6bd25871482e26b2e2eb8ff5a0e11d16134 (patch) | |
tree | a8bcb8860a8c0882ddec958c66351da8050b612b | |
parent | 6b0a86d66540ebee5d15164e98b9f2160f7adf54 (diff) | |
download | ras-tools-a4e0b6bd25871482e26b2e2eb8ff5a0e11d16134.tar.gz |
einj_mem_uc: Fix file descriptor leak for copyin test
The copyin test fails at just over 1000 iterations because it can no
longer open new file descriptors.
The problem is that the test opens a file, and closes at the end of
the function. But since successful recover sends a SIGBUS, the close
is never executed.
Make the file descriptor global and close it in the main() function
after the normal or SIGBUS return paths.
Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r-- | einj_mem_uc.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/einj_mem_uc.c b/einj_mem_uc.c index 9fdc61d..ad9c607 100644 --- a/einj_mem_uc.c +++ b/einj_mem_uc.c @@ -294,23 +294,25 @@ int trigger_memcpy(char *addr) return 0; } +static int copyin_fd = -1; + int trigger_copyin(char *addr) { - int fd, ret; + int ret; char filename[] = "/tmp/einj-XXXXXX"; - if ((fd = mkstemp(filename)) == -1) { + if ((copyin_fd = mkstemp(filename)) == -1) { fprintf(stderr, "%s: couldn't make temp file\n", progname); return -1; } (void)unlink(filename); - if ((ret = write(fd, addr - memcpy_runup, memcpy_size) != memcpy_size)) { + if ((ret = write(copyin_fd, addr - memcpy_runup, memcpy_size) != memcpy_size)) { if (ret == -1) fprintf(stderr, "%s: couldn't write temp file (errno=%d)\n", progname, errno); else fprintf(stderr, "%s: short (%d bytes) write to temp file\n", ret, progname); } - close(fd); + return 0; } @@ -530,6 +532,11 @@ int main(int argc, char **argv) } } + if (copyin_fd != -1) { + close(copyin_fd); + copyin_fd = -1; + } + if (pcfile) { fclose(pcfile); pcfile = NULL; |