* [PATCH] irda: handle out of memory errors
@ 2006-12-19 8:55 Akinobu Mita
2006-12-19 22:44 ` Samuel Ortiz
0 siblings, 1 reply; 3+ messages in thread
From: Akinobu Mita @ 2006-12-19 8:55 UTC (permalink / raw)
To: netdev; +Cc: Samuel Ortiz
This patch checks return value of memory allocation functions
for irda subsystem and fixes memory leaks in error cases.
Cc: Samuel Ortiz <samuel@sortiz.org>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
net/irda/irias_object.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
Index: 2.6-mm/net/irda/irias_object.c
===================================================================
--- 2.6-mm.orig/net/irda/irias_object.c
+++ 2.6-mm/net/irda/irias_object.c
@@ -91,6 +91,12 @@ struct ias_object *irias_new_object( cha
obj->magic = IAS_OBJECT_MAGIC;
obj->name = strndup(name, IAS_MAX_CLASSNAME);
+ if (!obj->name) {
+ IRDA_WARNING("%s(), Unable to allocate name!\n",
+ __FUNCTION__);
+ kfree(obj);
+ return NULL;
+ }
obj->id = id;
/* Locking notes : the attrib spinlock has lower precendence
@@ -101,6 +107,7 @@ struct ias_object *irias_new_object( cha
if (obj->attribs == NULL) {
IRDA_WARNING("%s(), Unable to allocate attribs!\n",
__FUNCTION__);
+ kfree(obj->name);
kfree(obj);
return NULL;
}
@@ -357,6 +364,15 @@ void irias_add_integer_attrib(struct ias
/* Insert value */
attrib->value = irias_new_integer_value(value);
+ if (!attrib->name || !attrib->value) {
+ IRDA_WARNING("%s: Unable to allocate attribute!\n",
+ __FUNCTION__);
+ if (attrib->value)
+ irias_delete_value(attrib->value);
+ kfree(attrib->name);
+ kfree(attrib);
+ return;
+ }
irias_add_attrib(obj, attrib, owner);
}
@@ -391,6 +407,15 @@ void irias_add_octseq_attrib(struct ias_
attrib->name = strndup(name, IAS_MAX_ATTRIBNAME);
attrib->value = irias_new_octseq_value( octets, len);
+ if (!attrib->name || !attrib->value) {
+ IRDA_WARNING("%s: Unable to allocate attribute!\n",
+ __FUNCTION__);
+ if (attrib->value)
+ irias_delete_value(attrib->value);
+ kfree(attrib->name);
+ kfree(attrib);
+ return;
+ }
irias_add_attrib(obj, attrib, owner);
}
@@ -424,6 +449,15 @@ void irias_add_string_attrib(struct ias_
attrib->name = strndup(name, IAS_MAX_ATTRIBNAME);
attrib->value = irias_new_string_value(value);
+ if (!attrib->name || !attrib->value) {
+ IRDA_WARNING("%s: Unable to allocate attribute!\n",
+ __FUNCTION__);
+ if (attrib->value)
+ irias_delete_value(attrib->value);
+ kfree(attrib->name);
+ kfree(attrib);
+ return;
+ }
irias_add_attrib(obj, attrib, owner);
}
@@ -473,6 +507,12 @@ struct ias_value *irias_new_string_value
value->type = IAS_STRING;
value->charset = CS_ASCII;
value->t.string = strndup(string, IAS_MAX_STRING);
+ if (!value->t.string) {
+ IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__);
+ kfree(value);
+ return NULL;
+ }
+
value->len = strlen(value->t.string);
return value;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] irda: handle out of memory errors
2006-12-19 8:55 [PATCH] irda: handle out of memory errors Akinobu Mita
@ 2006-12-19 22:44 ` Samuel Ortiz
2007-02-07 8:11 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Samuel Ortiz @ 2006-12-19 22:44 UTC (permalink / raw)
To: Akinobu Mita; +Cc: netdev, David S. Miller
On Tue, Dec 19, 2006 at 05:55:09PM +0900, Akinobu Mita wrote:
> This patch checks return value of memory allocation functions
> for irda subsystem and fixes memory leaks in error cases.
>
> Cc: Samuel Ortiz <samuel@sortiz.org>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
That looks correct, thanks for the patch.
Signed-off-by: Samuel Ortiz <samuel@sortiz.org>
Cheers,
Samuel.
>
> ---
> net/irda/irias_object.c | 40 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
>
> Index: 2.6-mm/net/irda/irias_object.c
> ===================================================================
> --- 2.6-mm.orig/net/irda/irias_object.c
> +++ 2.6-mm/net/irda/irias_object.c
> @@ -91,6 +91,12 @@ struct ias_object *irias_new_object( cha
>
> obj->magic = IAS_OBJECT_MAGIC;
> obj->name = strndup(name, IAS_MAX_CLASSNAME);
> + if (!obj->name) {
> + IRDA_WARNING("%s(), Unable to allocate name!\n",
> + __FUNCTION__);
> + kfree(obj);
> + return NULL;
> + }
> obj->id = id;
>
> /* Locking notes : the attrib spinlock has lower precendence
> @@ -101,6 +107,7 @@ struct ias_object *irias_new_object( cha
> if (obj->attribs == NULL) {
> IRDA_WARNING("%s(), Unable to allocate attribs!\n",
> __FUNCTION__);
> + kfree(obj->name);
> kfree(obj);
> return NULL;
> }
> @@ -357,6 +364,15 @@ void irias_add_integer_attrib(struct ias
>
> /* Insert value */
> attrib->value = irias_new_integer_value(value);
> + if (!attrib->name || !attrib->value) {
> + IRDA_WARNING("%s: Unable to allocate attribute!\n",
> + __FUNCTION__);
> + if (attrib->value)
> + irias_delete_value(attrib->value);
> + kfree(attrib->name);
> + kfree(attrib);
> + return;
> + }
>
> irias_add_attrib(obj, attrib, owner);
> }
> @@ -391,6 +407,15 @@ void irias_add_octseq_attrib(struct ias_
> attrib->name = strndup(name, IAS_MAX_ATTRIBNAME);
>
> attrib->value = irias_new_octseq_value( octets, len);
> + if (!attrib->name || !attrib->value) {
> + IRDA_WARNING("%s: Unable to allocate attribute!\n",
> + __FUNCTION__);
> + if (attrib->value)
> + irias_delete_value(attrib->value);
> + kfree(attrib->name);
> + kfree(attrib);
> + return;
> + }
>
> irias_add_attrib(obj, attrib, owner);
> }
> @@ -424,6 +449,15 @@ void irias_add_string_attrib(struct ias_
> attrib->name = strndup(name, IAS_MAX_ATTRIBNAME);
>
> attrib->value = irias_new_string_value(value);
> + if (!attrib->name || !attrib->value) {
> + IRDA_WARNING("%s: Unable to allocate attribute!\n",
> + __FUNCTION__);
> + if (attrib->value)
> + irias_delete_value(attrib->value);
> + kfree(attrib->name);
> + kfree(attrib);
> + return;
> + }
>
> irias_add_attrib(obj, attrib, owner);
> }
> @@ -473,6 +507,12 @@ struct ias_value *irias_new_string_value
> value->type = IAS_STRING;
> value->charset = CS_ASCII;
> value->t.string = strndup(string, IAS_MAX_STRING);
> + if (!value->t.string) {
> + IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__);
> + kfree(value);
> + return NULL;
> + }
> +
> value->len = strlen(value->t.string);
>
> return value;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] irda: handle out of memory errors
2006-12-19 22:44 ` Samuel Ortiz
@ 2007-02-07 8:11 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2007-02-07 8:11 UTC (permalink / raw)
To: samuel; +Cc: akinobu.mita, netdev
From: Samuel Ortiz <samuel@sortiz.org>
Date: Wed, 20 Dec 2006 00:44:22 +0200
> On Tue, Dec 19, 2006 at 05:55:09PM +0900, Akinobu Mita wrote:
> > This patch checks return value of memory allocation functions
> > for irda subsystem and fixes memory leaks in error cases.
> >
> > Cc: Samuel Ortiz <samuel@sortiz.org>
> > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> That looks correct, thanks for the patch.
>
> Signed-off-by: Samuel Ortiz <samuel@sortiz.org>
Applied, thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-02-07 8:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-19 8:55 [PATCH] irda: handle out of memory errors Akinobu Mita
2006-12-19 22:44 ` Samuel Ortiz
2007-02-07 8:11 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).