Added missing malloc failure checks

This commit is contained in:
Landon Curt Noll
2021-02-04 15:28:51 -08:00
parent 229345ade8
commit 8b7e01f426
3 changed files with 18 additions and 2 deletions

8
hist.c
View File

@@ -745,10 +745,18 @@ hist_saveline(char *line, int len)
* Add the line to the end of the history table.
*/
hp = malloc(sizeof(HIST));
if (hp == NULL) {
fprintf(stderr, "Out of memory adding line to the history table #0\n");
return;
}
hp->next = NULL;
hp->prev = NULL;
hp->len = len;
hp->data = malloc(len);
if (hp->data == NULL) {
fprintf(stderr, "Out of memory adding line to the history table #1\n");
return;
}
memcpy(hp->data, line, len);
HS.curhist = ++HS.histcount;
if (!hist_first)