netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Samuel Ortiz <samuel@sortiz.org>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] irda: handle out of memory errors
Date: Wed, 20 Dec 2006 00:44:22 +0200	[thread overview]
Message-ID: <20061219224422.GB4274@sortiz.org> (raw)
In-Reply-To: <20061219085509.GK4049@APFDCB5C>

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;

  reply	other threads:[~2006-12-19 23:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-19  8:55 [PATCH] irda: handle out of memory errors Akinobu Mita
2006-12-19 22:44 ` Samuel Ortiz [this message]
2007-02-07  8:11   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061219224422.GB4274@sortiz.org \
    --to=samuel@sortiz.org \
    --cc=akinobu.mita@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).