From f453291a75840c190fff8442e04f34a0dee0f096 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 14 Feb 2009 19:01:21 -0800 Subject: [PATCH] Fix libstand's filesystem close callback. The passed file pointer's f_fsdata field must be NULLed out. --- lib/libstand/gzipfs.c | 11 +++++++---- lib/libstand/hammerread.c | 6 ++++-- lib/libstand/nfs.c | 4 ++-- lib/libstand/splitfs.c | 10 +++++++--- lib/libstand/tftp.c | 1 + lib/libstand/ufs.c | 4 ++-- lib/libstand/zipfs.c | 9 ++++++--- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/libstand/gzipfs.c b/lib/libstand/gzipfs.c index 8f6aaa0d90..f5b1c89ad9 100644 --- a/lib/libstand/gzipfs.c +++ b/lib/libstand/gzipfs.c @@ -233,10 +233,13 @@ static int zf_close(struct open_file *f) { struct z_file *zf = (struct z_file *)f->f_fsdata; - - inflateEnd(&(zf->zf_zstream)); - close(zf->zf_rawfd); - free(zf); + + f->f_fsdata = NULL; + if (zf) { + inflateEnd(&(zf->zf_zstream)); + close(zf->zf_rawfd); + free(zf); + } return(0); } diff --git a/lib/libstand/hammerread.c b/lib/libstand/hammerread.c index d3899ea27f..86e86aee0b 100644 --- a/lib/libstand/hammerread.c +++ b/lib/libstand/hammerread.c @@ -909,9 +909,11 @@ hammer_close(struct open_file *f) { struct hfile *hf = f->f_fsdata; - hclose(&hf->hfs); f->f_fsdata = NULL; - free(hf); + if (hf) { + hclose(&hf->hfs); + free(hf); + } return (0); } diff --git a/lib/libstand/nfs.c b/lib/libstand/nfs.c index f6d1930f00..1ee2fd3c06 100644 --- a/lib/libstand/nfs.c +++ b/lib/libstand/nfs.c @@ -551,9 +551,9 @@ nfs_close(struct open_file *f) printf("nfs_close: fp=0x%lx\n", (u_long)fp); #endif - if (fp != &nfs_root_node && fp) + f->f_fsdata = NULL; + if (fp && fp != &nfs_root_node) free(fp); - f->f_fsdata = (void *)0; return (0); } diff --git a/lib/libstand/splitfs.c b/lib/libstand/splitfs.c index cb0af2b515..76b5dee9ed 100644 --- a/lib/libstand/splitfs.c +++ b/lib/libstand/splitfs.c @@ -156,9 +156,13 @@ splitfs_close(struct open_file *f) struct split_file *sf; sf = (struct split_file *)f->f_fsdata; - fd = sf->curfd; - split_file_destroy(sf); - return(close(fd)); + f->f_fsdata = NULL; + if (sf) { + fd = sf->curfd; + split_file_destroy(sf); + return(close(fd)); + } + return(0); } static int diff --git a/lib/libstand/tftp.c b/lib/libstand/tftp.c index 5848079477..0e09eac5e7 100644 --- a/lib/libstand/tftp.c +++ b/lib/libstand/tftp.c @@ -358,6 +358,7 @@ tftp_close(struct open_file *f) if (tftpfile) { free(tftpfile->path); free(tftpfile); + f->f_fsdata = NULL; } return (0); } diff --git a/lib/libstand/ufs.c b/lib/libstand/ufs.c index 9b75cc1739..f59cd2973a 100644 --- a/lib/libstand/ufs.c +++ b/lib/libstand/ufs.c @@ -595,8 +595,8 @@ ufs_close(struct open_file *f) struct file *fp = (struct file *)f->f_fsdata; int level; - f->f_fsdata = (void *)0; - if (fp == (struct file *)0) + f->f_fsdata = NULL; + if (fp == NULL) return (0); for (level = 0; level < NIADDR; level++) { diff --git a/lib/libstand/zipfs.c b/lib/libstand/zipfs.c index 7635f91a1f..5a725dc7f9 100644 --- a/lib/libstand/zipfs.c +++ b/lib/libstand/zipfs.c @@ -235,9 +235,12 @@ zf_close(struct open_file *f) { struct z_file *zf = (struct z_file *)f->f_fsdata; - inflateEnd(&(zf->zf_zstream)); - close(zf->zf_rawfd); - free(zf); + f->f_fsdata = NULL; + if (zf) { + inflateEnd(&(zf->zf_zstream)); + close(zf->zf_rawfd); + free(zf); + } return(0); } -- 2.41.0