summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Yanfei <zhangyanfei@cn.fujitsu.com>2013-03-14 01:16:25 +0800
committerSimon Horman <horms@verge.net.au>2013-03-14 09:36:51 +0100
commit5db7ba5dbc87daf361397ac727f146e0565db1a9 (patch)
tree24f1eed59f04d881aa04de8cb4d10aa5adb51138
parent51438a32f6a0f09a358742f06196d14e4ad0ccab (diff)
downloadkexec-tools-5db7ba5dbc87daf361397ac727f146e0565db1a9.tar.gz
kexec: check size before trying the malloc
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@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--kexec/kexec.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 3ef6f0d4..494c5b3f 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));