Skip to content

Commit

Permalink
crypto: tcrypt - Fix memory leak in test_cipher
Browse files Browse the repository at this point in the history
Coverity CID: 2306 & 2307 RESOURCE_LEAK

In the second for loop in test_cipher(), data is allocated space with
kzalloc() and is only ever freed in an error case.
Looking at this loop, data is written to this memory but nothing seems
to read from it. 
So here is a patch removing the allocation, I think this is the right
fix.

Only compile tested.

Signed-off-by: Darren Jenkins <darrenrjenkins@gmailcom>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
Darren Jenkins authored and herbertx committed Jul 8, 2008
1 parent 7b51ba3 commit dbb018c
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions crypto/tcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,6 @@ static void test_cipher(char *algo, int enc,
j = 0;
for (i = 0; i < tcount; i++) {

data = kzalloc(template[i].ilen, GFP_KERNEL);
if (!data)
continue;

memcpy(data, template[i].input, template[i].ilen);

if (template[i].iv)
memcpy(iv, template[i].iv, MAX_IVLEN);
else
Expand All @@ -613,10 +607,8 @@ static void test_cipher(char *algo, int enc,
printk("setkey() failed flags=%x\n",
crypto_ablkcipher_get_flags(tfm));

if (!template[i].fail) {
kfree(data);
if (!template[i].fail)
goto out;
}
}

temp = 0;
Expand Down

0 comments on commit dbb018c

Please sign in to comment.