From 049e1954049db9ad2df9b4890919a5aa2b70f1fd Mon Sep 17 00:00:00 2001 From: Marcelo Araujo Date: Wed, 3 May 2017 13:57:31 +0000 Subject: [PATCH] Free the memory allocated to trackbuf before exiting, it might fix a potential memory leak. Submitted by: trix@juniper.net MFC after: 2 weeks. Differential Revision: https://reviews.freebsd.org/D9856 --- usr.sbin/fdread/fdread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usr.sbin/fdread/fdread.c b/usr.sbin/fdread/fdread.c index f3c2d9147b9c..a0cdd85336cb 100644 --- a/usr.sbin/fdread/fdread.c +++ b/usr.sbin/fdread/fdread.c @@ -184,6 +184,7 @@ doread(int fd, FILE *of, const char *_devname) if (rv == 0) { /* EOF? */ warnx("premature EOF after %u bytes", nbytes); + free(trackbuf); return (EX_OK); } if ((unsigned)rv == tracksize) { @@ -215,6 +216,7 @@ doread(int fd, FILE *of, const char *_devname) if (!quiet) putc('\n', stderr); perror("non-IO error"); + free(trackbuf); return (EX_OSERR); } if (ioctl(fd, FD_GSTAT, &fdcs) == -1) @@ -233,6 +235,7 @@ doread(int fd, FILE *of, const char *_devname) if (!recover) { if (!quiet) putc('\n', stderr); + free(trackbuf); return (EX_IOERR); } memset(trackbuf, fillbyte, secsize); @@ -284,6 +287,7 @@ doread(int fd, FILE *of, const char *_devname) continue; } } + free(trackbuf); if (!quiet) { putc('\n', stderr); if (nerrs)