* Avoid memory leak by allocate readbuf on the stack, not by malloc. * close file descriptor explicitly before return.
Signed-off-by: Wei,Jiangang <weijg.f...@cn.fujitsu.com> --- testcases/kernel/mem/mmapstress/mmapstress01.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 0baf0e2..ed1466a 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -602,9 +602,9 @@ int fileokay(char *file, uchar_t * expbuf) struct stat statbuf; #endif /* LARGE_FILE */ size_t mapsize; - uchar_t *readbuf; unsigned mappages; unsigned pagesize = sysconf(_SC_PAGE_SIZE); + char readbuf[pagesize]; int fd; int cnt; unsigned i, j; @@ -641,7 +641,6 @@ int fileokay(char *file, uchar_t * expbuf) perror("lseek"); anyfail(); } - readbuf = malloc(pagesize); if (statbuf.st_size - sparseoffset > SIZE_MAX) { fprintf(stderr, "size_t overflow when setting up map\n"); @@ -668,6 +667,7 @@ int fileokay(char *file, uchar_t * expbuf) (void)fprintf(stderr, "read %d of %ld bytes\n", (i * pagesize) + cnt, (long)mapsize); + close(fd); return 0; } } @@ -688,6 +688,7 @@ int fileokay(char *file, uchar_t * expbuf) "(fsize %ld)\n", i, j, statbuf.st_size); #endif /* LARGE_FILE */ + close(fd); return 0; } } -- 1.9.3 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list