client: check if memory allocation fails

This commit is contained in:
Miroslav Lichvar 2015-08-05 15:47:00 +02:00
parent 12c434fdc0
commit ad34b26955
2 changed files with 8 additions and 7 deletions

View file

@ -44,7 +44,7 @@ OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o mkdirpp.o \
EXTRA_OBJS=@EXTRA_OBJECTS@ EXTRA_OBJS=@EXTRA_OBJECTS@
CLI_OBJS = client.o nameserv.o getdate.o cmdparse.o \ CLI_OBJS = client.o cmdparse.o getdate.o memory.o nameserv.o \
pktlength.o util.o $(HASH_OBJ) pktlength.o util.o $(HASH_OBJ)
ALL_OBJS = $(OBJS) $(EXTRA_OBJS) $(CLI_OBJS) ALL_OBJS = $(OBJS) $(EXTRA_OBJS) $(CLI_OBJS)

View file

@ -32,6 +32,7 @@
#include "candm.h" #include "candm.h"
#include "logging.h" #include "logging.h"
#include "memory.h"
#include "nameserv.h" #include "nameserv.h"
#include "hash.h" #include "hash.h"
#include "getdate.h" #include "getdate.h"
@ -112,7 +113,7 @@ read_line(void)
line[sizeof(line) - 1] = '\0'; line[sizeof(line) - 1] = '\0';
add_history(cmd); add_history(cmd);
/* free the buffer allocated by readline */ /* free the buffer allocated by readline */
free(cmd); Free(cmd);
} else { } else {
/* simulate the user has entered an empty line */ /* simulate the user has entered an empty line */
*line = '\0'; *line = '\0';
@ -1090,7 +1091,7 @@ process_cmd_password(CMD_Request *msg, char *line)
if (password) { if (password) {
for (i = 0; i < password_length; i++) for (i = 0; i < password_length; i++)
password[i] = 0; password[i] = 0;
free(password); Free(password);
password = NULL; password = NULL;
} }
@ -1108,7 +1109,7 @@ process_cmd_password(CMD_Request *msg, char *line)
password_length = UTI_DecodePasswordFromText(p); password_length = UTI_DecodePasswordFromText(p);
if (password_length > 0) { if (password_length > 0) {
password = malloc(password_length); password = Malloc(password_length);
memcpy(password, p, password_length); memcpy(password, p, password_length);
} }
@ -2738,7 +2739,7 @@ process_args(int argc, char **argv, int multi)
total_length += strlen(argv[i]) + 1; total_length += strlen(argv[i]) + 1;
} }
line = (char *) malloc((2 + total_length) * sizeof(char)); line = (char *) Malloc((2 + total_length) * sizeof(char));
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
line[0] = '\0'; line[0] = '\0';
@ -2757,7 +2758,7 @@ process_args(int argc, char **argv, int multi)
break; break;
} }
free(line); Free(line);
return ret; return ret;
} }
@ -2884,7 +2885,7 @@ main(int argc, char **argv)
close_io(); close_io();
free(password); Free(password);
return !ret; return !ret;
} }