diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-14 01:25:31 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-14 01:25:31 +0000 |
commit | 4dc1d25a30825091b0a285eb3b36121a066b30ee (patch) | |
tree | 4b4341e85e7f558c11662e04ed171e758ed64af1 | |
parent | f36635cec6da728fe06b849089ce2f6c1690dc67 (diff) | |
download | busybox-w32-4dc1d25a30825091b0a285eb3b36121a066b30ee.tar.gz busybox-w32-4dc1d25a30825091b0a285eb3b36121a066b30ee.tar.bz2 busybox-w32-4dc1d25a30825091b0a285eb3b36121a066b30ee.zip |
Fix some memory allocation problems
-rw-r--r-- | editors/sed.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/editors/sed.c b/editors/sed.c index 75ed53eb7..6dbb1fb8f 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -1057,7 +1057,11 @@ static void process_file(FILE * file) | |||
1057 | hold_space_size = strlen(hold_space); | 1057 | hold_space_size = strlen(hold_space); |
1058 | } | 1058 | } |
1059 | hold_space = xrealloc(hold_space, hold_space_size + strlen(pattern_space) + 2); | 1059 | hold_space = xrealloc(hold_space, hold_space_size + strlen(pattern_space) + 2); |
1060 | strcat(hold_space, "\n"); | 1060 | if (hold_space_size) { |
1061 | strcat(hold_space, "\n"); | ||
1062 | } else { | ||
1063 | hold_space[0] = '\n'; | ||
1064 | } | ||
1061 | strcat(hold_space, pattern_space); | 1065 | strcat(hold_space, pattern_space); |
1062 | break; | 1066 | break; |
1063 | } | 1067 | } |
@@ -1103,6 +1107,7 @@ static void process_file(FILE * file) | |||
1103 | 1107 | ||
1104 | if (deleted) | 1108 | if (deleted) |
1105 | break; | 1109 | break; |
1110 | |||
1106 | } | 1111 | } |
1107 | 1112 | ||
1108 | /* we will print the line unless we were told to be quiet or if the | 1113 | /* 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) | |||
1155 | else { | 1160 | else { |
1156 | char *str_cmd = strdup(argv[optind]); | 1161 | char *str_cmd = strdup(argv[optind]); |
1157 | 1162 | ||
1158 | add_cmd_str(strdup(str_cmd)); | 1163 | add_cmd_str(strd_cmd); |
1159 | free(str_cmd); | 1164 | free(str_cmd); |
1160 | optind++; | 1165 | optind++; |
1161 | } | 1166 | } |