Re: [CHECKER] 32 Memory Leaks on Error Paths

From: Chris Wright
Date: Mon Sep 22 2003 - 18:00:15 EST


* David Yu Chen (dychen@xxxxxxxxxxxx) wrote:
> [FILE: 2.6.0-test5/drivers/telephony/ixj_pcmcia.c]
> [FUNC: ixj_attach]
> [LINES: 53-64]
> [VAR: link]
> 48: client_reg_t client_reg;
> 49: dev_link_t *link;
> 50: int ret;
> 51: DEBUG(0, "ixj_attach()\n");
> 52: /* Create new ixj device */
> START -->
> 53: link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
> 54: if (!link)
> 55: return NULL;
> 56: memset(link, 0, sizeof(struct dev_link_t));
> 57: link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
> 58: link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
> 59: link->io.IOAddrLines = 3;
> 60: link->conf.Vcc = 50;
> 61: link->conf.IntType = INT_MEMORY_AND_IO;
> 62: link->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
> 63: if (!link->priv)
> END -->
> 64: return NULL;

Yes, this is a bug. Patch below.

thanks,
-chris

===== drivers/telephony/ixj_pcmcia.c 1.6 vs edited =====
--- 1.6/drivers/telephony/ixj_pcmcia.c Sat Aug 16 13:22:52 2003
+++ edited/drivers/telephony/ixj_pcmcia.c Mon Sep 22 15:38:40 2003
@@ -60,8 +60,10 @@
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
link->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
- if (!link->priv)
+ if (!link->priv) {
+ kfree(link);
return NULL;
+ }
memset(link->priv, 0, sizeof(struct ixj_info_t));
/* Register with Card Services */
link->next = dev_list;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/