Skip to content

Commit fa865ba

Browse files
wenwenwang1davem330
authored andcommitted
firestream: fix memory leaks
In fs_open(), 'vcc' is allocated through kmalloc() and assigned to 'atm_vcc->dev_data.' In the following execution, if an error occurs, e.g., there is no more free channel, an error code EBUSY or ENOMEM will be returned. However, 'vcc' is not deallocated, leading to memory leaks. Note that, in normal cases where fs_open() returns 0, 'vcc' will be deallocated in fs_close(). But, if fs_open() fails, there is no guarantee that fs_close() will be invoked. To fix this issue, deallocate 'vcc' before the error code is returned. Signed-off-by: Wenwen Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6badad1 commit fa865ba

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/atm/firestream.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ static int fs_open(struct atm_vcc *atm_vcc)
912912
}
913913
if (!to) {
914914
printk ("No more free channels for FS50..\n");
915+
kfree(vcc);
915916
return -EBUSY;
916917
}
917918
vcc->channo = dev->channo;
@@ -922,6 +923,7 @@ static int fs_open(struct atm_vcc *atm_vcc)
922923
if (((DO_DIRECTION(rxtp) && dev->atm_vccs[vcc->channo])) ||
923924
( DO_DIRECTION(txtp) && test_bit (vcc->channo, dev->tx_inuse))) {
924925
printk ("Channel is in use for FS155.\n");
926+
kfree(vcc);
925927
return -EBUSY;
926928
}
927929
}
@@ -935,6 +937,7 @@ static int fs_open(struct atm_vcc *atm_vcc)
935937
tc, sizeof (struct fs_transmit_config));
936938
if (!tc) {
937939
fs_dprintk (FS_DEBUG_OPEN, "fs: can't alloc transmit_config.\n");
940+
kfree(vcc);
938941
return -ENOMEM;
939942
}
940943

0 commit comments

Comments
 (0)