]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
prf-plus: Fix a potential memory leak if get_bytes() fails
authorTobias Brunner <tobias@strongswan.org>
Fri, 18 Oct 2019 13:11:26 +0000 (15:11 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 21 Oct 2019 10:22:22 +0000 (12:22 +0200)
src/libstrongswan/crypto/prf_plus.c

index 7d2b5217cdda5ba84719fa47d191cb95f43f6a15..4668f496860a9d979af2a97b3badea304875fa48 100644 (file)
@@ -103,12 +103,12 @@ METHOD(prf_plus_t, get_bytes, bool,
 METHOD(prf_plus_t, allocate_bytes, bool,
        private_prf_plus_t *this, size_t length, chunk_t *chunk)
 {
-       if (length)
+       *chunk = chunk_alloc(length);
+       if (!get_bytes(this, length, chunk->ptr))
        {
-               *chunk = chunk_alloc(length);
-               return get_bytes(this, length, chunk->ptr);
+               chunk_free(chunk);
+               return FALSE;
        }
-       *chunk = chunk_empty;
        return TRUE;
 }