From 2429629e3b2673e21e5d4cf54fdc1c3eacab1679 Mon Sep 17 00:00:00 2001 From: tbeu Date: Tue, 24 Oct 2017 17:44:51 +0200 Subject: [PATCH] Fix usage after release (as reported by PVS-Studio) V774 The '(char *) buf' pointer was used after the memory was released. tpl.c 1027 --- src/tpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tpl.c b/src/tpl.c index 0cc2788..e37b052 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -1021,13 +1021,13 @@ TPL_API int tpl_dump(tpl_node *r, int mode, ...) { } else if (rc == -1) { if (errno == EINTR || errno == EAGAIN) continue; tpl_hook.oops("error writing to fd %d: %s\n", fd, strerror(errno)); - free(buf); /* attempt to rewind partial write to a regular file */ if (fstat(fd,&sbuf) == 0 && S_ISREG(sbuf.st_mode)) { if (ftruncate(fd,sbuf.st_size - (bufv-(char*)buf)) == -1) { tpl_hook.oops("can't rewind: %s\n", strerror(errno)); } } + free(buf); return -1; } } while (sz > 0);