venus: fix memory leak 93/12293/3
authorMarcio Barbosa <mbarbosa@sinenomine.net>
Tue, 31 May 2016 12:08:08 +0000 (09:08 -0300)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 14 Sep 2018 02:43:37 +0000 (22:43 -0400)
In GetPrefCmd, when we request server prefs from the kernel and our
output buffer is not big enough, pioctl() will return E2BIG and we
allocate more memory and try again. However, if the size of the output
buffer reaches 16k bytes and this space is still not enough (or if
pioctl fails and errno != E2BIG), we return without releasing the
memory that was previously allocated.

To fix this problem, free our output buffer when this happens.

Change-Id: Ib34cb12629528ddf2a763386f0ac5494eb8be695
Reviewed-on: https://gerrit.openafs.org/12293
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/venus/fs.c

index 39f266a..1ef37b1 100644 (file)
@@ -3326,6 +3326,9 @@ GetPrefCmd(struct cmd_syndesc *as, void *arock)
            if (code) {
                if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
                    perror("getserverprefs pioctl");
+                   if (blob.out != space) {
+                       free(blob.out);
+                   }
                    return 1;
                }
                blob.out_size *= 2;