diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2007-02-07 03:11:11 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-02-08 15:39:07 -0500 |
commit | bb5aa42734e72b3f02fc0b3cdd6105083f9880f1 (patch) | |
tree | 3aa983ae94ce1383426455439610e664823dcb7f /net/irda/irias_object.c | |
parent | 22f8cde5bc336fd19603bb8c4572b33d14f14f87 (diff) |
[IRDA]: handle out of memory errors
This patch checks return value of memory allocation functions
for irda subsystem and fixes memory leaks in error cases.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Samuel Ortiz <samuel@sortiz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/irda/irias_object.c')
-rw-r--r-- | net/irda/irias_object.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c index b1ee99a59c0c..2a571b43ebec 100644 --- a/net/irda/irias_object.c +++ b/net/irda/irias_object.c | |||
@@ -91,6 +91,12 @@ struct ias_object *irias_new_object( char *name, int id) | |||
91 | 91 | ||
92 | obj->magic = IAS_OBJECT_MAGIC; | 92 | obj->magic = IAS_OBJECT_MAGIC; |
93 | obj->name = strndup(name, IAS_MAX_CLASSNAME); | 93 | obj->name = strndup(name, IAS_MAX_CLASSNAME); |
94 | if (!obj->name) { | ||
95 | IRDA_WARNING("%s(), Unable to allocate name!\n", | ||
96 | __FUNCTION__); | ||
97 | kfree(obj); | ||
98 | return NULL; | ||
99 | } | ||
94 | obj->id = id; | 100 | obj->id = id; |
95 | 101 | ||
96 | /* Locking notes : the attrib spinlock has lower precendence | 102 | /* Locking notes : the attrib spinlock has lower precendence |
@@ -101,6 +107,7 @@ struct ias_object *irias_new_object( char *name, int id) | |||
101 | if (obj->attribs == NULL) { | 107 | if (obj->attribs == NULL) { |
102 | IRDA_WARNING("%s(), Unable to allocate attribs!\n", | 108 | IRDA_WARNING("%s(), Unable to allocate attribs!\n", |
103 | __FUNCTION__); | 109 | __FUNCTION__); |
110 | kfree(obj->name); | ||
104 | kfree(obj); | 111 | kfree(obj); |
105 | return NULL; | 112 | return NULL; |
106 | } | 113 | } |
@@ -357,6 +364,15 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value, | |||
357 | 364 | ||
358 | /* Insert value */ | 365 | /* Insert value */ |
359 | attrib->value = irias_new_integer_value(value); | 366 | attrib->value = irias_new_integer_value(value); |
367 | if (!attrib->name || !attrib->value) { | ||
368 | IRDA_WARNING("%s: Unable to allocate attribute!\n", | ||
369 | __FUNCTION__); | ||
370 | if (attrib->value) | ||
371 | irias_delete_value(attrib->value); | ||
372 | kfree(attrib->name); | ||
373 | kfree(attrib); | ||
374 | return; | ||
375 | } | ||
360 | 376 | ||
361 | irias_add_attrib(obj, attrib, owner); | 377 | irias_add_attrib(obj, attrib, owner); |
362 | } | 378 | } |
@@ -391,6 +407,15 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets, | |||
391 | attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); | 407 | attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); |
392 | 408 | ||
393 | attrib->value = irias_new_octseq_value( octets, len); | 409 | attrib->value = irias_new_octseq_value( octets, len); |
410 | if (!attrib->name || !attrib->value) { | ||
411 | IRDA_WARNING("%s: Unable to allocate attribute!\n", | ||
412 | __FUNCTION__); | ||
413 | if (attrib->value) | ||
414 | irias_delete_value(attrib->value); | ||
415 | kfree(attrib->name); | ||
416 | kfree(attrib); | ||
417 | return; | ||
418 | } | ||
394 | 419 | ||
395 | irias_add_attrib(obj, attrib, owner); | 420 | irias_add_attrib(obj, attrib, owner); |
396 | } | 421 | } |
@@ -424,6 +449,15 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value, | |||
424 | attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); | 449 | attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); |
425 | 450 | ||
426 | attrib->value = irias_new_string_value(value); | 451 | attrib->value = irias_new_string_value(value); |
452 | if (!attrib->name || !attrib->value) { | ||
453 | IRDA_WARNING("%s: Unable to allocate attribute!\n", | ||
454 | __FUNCTION__); | ||
455 | if (attrib->value) | ||
456 | irias_delete_value(attrib->value); | ||
457 | kfree(attrib->name); | ||
458 | kfree(attrib); | ||
459 | return; | ||
460 | } | ||
427 | 461 | ||
428 | irias_add_attrib(obj, attrib, owner); | 462 | irias_add_attrib(obj, attrib, owner); |
429 | } | 463 | } |
@@ -473,6 +507,12 @@ struct ias_value *irias_new_string_value(char *string) | |||
473 | value->type = IAS_STRING; | 507 | value->type = IAS_STRING; |
474 | value->charset = CS_ASCII; | 508 | value->charset = CS_ASCII; |
475 | value->t.string = strndup(string, IAS_MAX_STRING); | 509 | value->t.string = strndup(string, IAS_MAX_STRING); |
510 | if (!value->t.string) { | ||
511 | IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); | ||
512 | kfree(value); | ||
513 | return NULL; | ||
514 | } | ||
515 | |||
476 | value->len = strlen(value->t.string); | 516 | value->len = strlen(value->t.string); |
477 | 517 | ||
478 | return value; | 518 | return value; |