apparmor: fix memory leak on buffer on error exit path
authorColin Ian King <colin.king@canonical.com>
Tue, 27 Mar 2018 13:35:58 +0000 (14:35 +0100)
committerJohn Johansen <john.johansen@canonical.com>
Sat, 31 Mar 2018 04:14:04 +0000 (21:14 -0700)
Currently on the error exit path the allocated buffer is not free'd
causing a memory leak. Fix this by kfree'ing it.

Detected by CoverityScan, CID#1466876 ("Resource leaks")

Fixes: 1180b4c757aa ("apparmor: fix dangling symlinks to policy rawdata after replacement")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/apparmorfs.c

index 62301ddbbe5ec05471dd969bd5f07a20c2c03ec8..f4308683c0af3911e9e193eae54f65b6cc87429d 100644 (file)
@@ -1497,8 +1497,10 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname)
        }
 
        error = snprintf(s, size, "raw_data/%s/%s", dirname, fname);
        }
 
        error = snprintf(s, size, "raw_data/%s/%s", dirname, fname);
-       if (error >= size || error < 0)
+       if (error >= size || error < 0) {
+               kfree(buffer);
                return ERR_PTR(-ENAMETOOLONG);
                return ERR_PTR(-ENAMETOOLONG);
+       }
 
        return buffer;
 }
 
        return buffer;
 }