From ad34b269551fbb8154124ce3303bf7d28c0a255a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 5 Aug 2015 15:47:00 +0200 Subject: [PATCH] client: check if memory allocation fails --- Makefile.in | 2 +- client.c | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile.in b/Makefile.in index 7778db8..c2784c4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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@ -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) ALL_OBJS = $(OBJS) $(EXTRA_OBJS) $(CLI_OBJS) diff --git a/client.c b/client.c index 32092f1..afa9abb 100644 --- a/client.c +++ b/client.c @@ -32,6 +32,7 @@ #include "candm.h" #include "logging.h" +#include "memory.h" #include "nameserv.h" #include "hash.h" #include "getdate.h" @@ -112,7 +113,7 @@ read_line(void) line[sizeof(line) - 1] = '\0'; add_history(cmd); /* free the buffer allocated by readline */ - free(cmd); + Free(cmd); } else { /* simulate the user has entered an empty line */ *line = '\0'; @@ -1090,7 +1091,7 @@ process_cmd_password(CMD_Request *msg, char *line) if (password) { for (i = 0; i < password_length; i++) password[i] = 0; - free(password); + Free(password); password = NULL; } @@ -1108,7 +1109,7 @@ process_cmd_password(CMD_Request *msg, char *line) password_length = UTI_DecodePasswordFromText(p); if (password_length > 0) { - password = malloc(password_length); + password = Malloc(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; } - line = (char *) malloc((2 + total_length) * sizeof(char)); + line = (char *) Malloc((2 + total_length) * sizeof(char)); for (i = 0; i < argc; i++) { line[0] = '\0'; @@ -2757,7 +2758,7 @@ process_args(int argc, char **argv, int multi) break; } - free(line); + Free(line); return ret; } @@ -2884,7 +2885,7 @@ main(int argc, char **argv) close_io(); - free(password); + Free(password); return !ret; }