[PATCH] kexec: check size before trying the malloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 14, 2013 at 01:16:25AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei at cn.fujitsu.com>
> 
> If size is zero, it is unnecessary to do the malloc operation.
> So checking size first is better than doing malloc first.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei at cn.fujitsu.com>

Thanks, applied.

> ---
>  kexec/kexec.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/kexec/kexec.c b/kexec/kexec.c
> index 3ef6f0d..494c5b3 100644
> --- a/kexec/kexec.c
> +++ b/kexec/kexec.c
> @@ -76,9 +76,9 @@ static char *xstrdup(const char *str)
>  void *xmalloc(size_t size)
>  {
>  	void *buf;
> -	buf = malloc(size);
>  	if (!size)
>  		return NULL;
> +	buf = malloc(size);
>  	if (!buf) {
>  		die("Cannot malloc %ld bytes: %s\n",
>  			size + 0UL, strerror(errno));
> -- 
> 1.7.1
> 



[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux