diff options
author | Zhang Yanfei <zhangyanfei@cn.fujitsu.com> | 2013-03-14 01:16:25 +0800 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2013-03-14 09:36:51 +0100 |
commit | 5db7ba5dbc87daf361397ac727f146e0565db1a9 (patch) | |
tree | 24f1eed59f04d881aa04de8cb4d10aa5adb51138 | |
parent | 51438a32f6a0f09a358742f06196d14e4ad0ccab (diff) | |
download | kexec-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.c | 2 |
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)); |