Fix some memory allocation problems

This commit is contained in:
Glenn L McGrath 2003-09-14 01:25:31 +00:00
parent f36635cec6
commit 4dc1d25a30

View File

@ -1057,7 +1057,11 @@ static void process_file(FILE * file)
hold_space_size = strlen(hold_space); hold_space_size = strlen(hold_space);
} }
hold_space = xrealloc(hold_space, hold_space_size + strlen(pattern_space) + 2); hold_space = xrealloc(hold_space, hold_space_size + strlen(pattern_space) + 2);
strcat(hold_space, "\n"); if (hold_space_size) {
strcat(hold_space, "\n");
} else {
hold_space[0] = '\n';
}
strcat(hold_space, pattern_space); strcat(hold_space, pattern_space);
break; break;
} }
@ -1103,6 +1107,7 @@ static void process_file(FILE * file)
if (deleted) if (deleted)
break; break;
} }
/* we will print the line unless we were told to be quiet or if the /* we will print the line unless we were told to be quiet or if the
@ -1155,7 +1160,7 @@ extern int sed_main(int argc, char **argv)
else { else {
char *str_cmd = strdup(argv[optind]); char *str_cmd = strdup(argv[optind]);
add_cmd_str(strdup(str_cmd)); add_cmd_str(strd_cmd);
free(str_cmd); free(str_cmd);
optind++; optind++;
} }