From e30c96ebdec4e8612f4102f9cd99d36488c66e5c Mon Sep 17 00:00:00 2001 From: NanXiao Date: Mon, 14 Jul 2014 16:34:49 +0800 Subject: Add empty pointer check in error cleanup If realloc fails, the curargv will be NULL. Closes #253 --- hiredis.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'hiredis.c') diff --git a/hiredis.c b/hiredis.c index a36c6f3..cc099af 100644 --- a/hiredis.c +++ b/hiredis.c @@ -895,12 +895,13 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) { return totlen; err: - while(argc--) - sdsfree(curargv[argc]); - free(curargv); + if (curargv) { + while(argc--) + sdsfree(curargv[argc]); + free(curargv); + } - if (curarg != NULL) - sdsfree(curarg); + sdsfree(curarg); /* No need to check cmd since it is the last statement that can fail, * but do it anyway to be as defensive as possible. */ -- cgit v1.2.3