diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-01-16 15:17:41 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-01-16 15:17:41 +0000 |
commit | 03c67e60a70083cf2ad3f60af5104127d22a9c8f (patch) | |
tree | 806ffc14476dce1cd029133c7c661fa73a44cb83 /src | |
parent | 41670f3559eeff21dcdfb32af98be2d367b9816d (diff) | |
download | mdevd-03c67e60a70083cf2ad3f60af5104127d22a9c8f.tar.xz |
Bugfix: fd leak on datafd errors when loading firmware. version: 0.1.0.1v0.1.0.1
Diffstat (limited to 'src')
-rw-r--r-- | src/mdevd/mdevd.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mdevd/mdevd.c b/src/mdevd/mdevd.c index 54e5cf6..e395cac 100644 --- a/src/mdevd/mdevd.c +++ b/src/mdevd/mdevd.c @@ -541,7 +541,7 @@ static inline void load_firmware (char const *fw, char const *sysdevpath) size_t fwbaselen = strlen(fwbase) ; size_t fwlen = strlen(fw) ; size_t sysdevpathlen = strlen(sysdevpath) ; - int fwfd, loadingfd ; + int fwfd, loadingfd, datafd ; char fwfn[fwbaselen + fwlen + 2] ; memcpy(fwfn, fwbase, fwbaselen) ; fwfn[fwbaselen] = '/' ; @@ -566,7 +566,6 @@ static inline void load_firmware (char const *fw, char const *sysdevpath) goto errclosel ; } { - int datafd ; char datafn[sysdevpathlen + 6] ; memcpy(datafn, sysdevpath, sysdevpathlen) ; memcpy(datafn + sysdevpathlen, "/data", 6) ; @@ -579,12 +578,12 @@ static inline void load_firmware (char const *fw, char const *sysdevpath) if (ndelay_off(datafd) < 0) { if (verbosity >= 2) strerr_warnwu2sys("ndelay_off ", datafn) ; - goto errload ; + goto errdata ; } if (fd_cat(fwfd, datafd) < 0) { if (verbosity >= 2) strerr_warnwu4sys("copy ", fwfn, " to ", datafn) ; - goto errload ; + goto errdata ; } fd_close(datafd) ; fd_write(loadingfd, "0", 1) ; @@ -593,6 +592,8 @@ static inline void load_firmware (char const *fw, char const *sysdevpath) fd_close(fwfd) ; return ; + errdata: + fd_close(datafd) ; errload: allwrite(loadingfd, "-1", 2) ; errclosel: |