]> granicus.if.org Git - sysstat/commitdiff
Fix ressource leak in sa_conv.c
authorSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 13 Jul 2015 14:08:17 +0000 (16:08 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 13 Jul 2015 14:11:05 +0000 (16:11 +0200)
The program could exit without freeing variable buffer. Yet this
variable could have been allocated on a previous iteration in the loop.
So free it before leaving.

CID #101316.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sa_conv.c

index 9c645b04b7225ee6c2df773f82be6fc823e7f247..7593ae41149ddae715b76b0bddc41b0245e31247 100644 (file)
--- a/sa_conv.c
+++ b/sa_conv.c
@@ -758,8 +758,13 @@ int upgrade_common_record(int fd, int stdfd, struct activity *act[],
                if ((p = get_activity_position(act, fal->id, RESUME_IF_NOT_FOUND)) < 0) {
                        /* An unknown activity should still be read and written */
                        size = (size_t) fal->size * (size_t) fal->nr * (size_t) fal->nr2;
-                       if (!size)
+                       if (!size) {
+                               /* Buffer may have been allocated from a previous iteration in the loop */
+                               if (buffer) {
+                                       free (buffer);
+                               }
                                return -1;
+                       }
                        SREALLOC(buffer, void, size);
                        sa_fread(fd, buffer, fal->size * fal->nr * fal->nr2, HARD_SIZE);
                        if (write(stdfd, (char *) buffer, size) != size) {