aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-08-31 12:51:54 +0100
committerRon Yorston <rmy@pobox.com>2023-08-31 12:51:54 +0100
commitf49e467a3986b888d5be3dd5c29ac4f3e21cba0e (patch)
treec99b060740169248d4a0ef32caba99441b04af1f
parentf498ba612f707d80c4c49d0a4fb58fd5c7c1b960 (diff)
parent2cc9d436e80632157b99e18d413a62b2d44d321a (diff)
downloadbusybox-w32-f49e467a3986b888d5be3dd5c29ac4f3e21cba0e.tar.gz
busybox-w32-f49e467a3986b888d5be3dd5c29ac4f3e21cba0e.tar.bz2
busybox-w32-f49e467a3986b888d5be3dd5c29ac4f3e21cba0e.zip
Merge branch 'busybox' into merge
-rw-r--r--coreutils/tsort.c20
-rw-r--r--shell/ash.c2
2 files changed, 18 insertions, 4 deletions
diff --git a/coreutils/tsort.c b/coreutils/tsort.c
index a451ed2ff..e1ee6bcd7 100644
--- a/coreutils/tsort.c
+++ b/coreutils/tsort.c
@@ -101,6 +101,10 @@ int tsort_main(int argc UNUSED_PARAM, char **argv)
101 ssize_t len; 101 ssize_t len;
102 struct node *a; 102 struct node *a;
103 int cycles; 103 int cycles;
104 unsigned i;
105#if ENABLE_FEATURE_CLEAN_UP
106 unsigned max_len;
107#endif
104 108
105 INIT_G(); 109 INIT_G();
106 110
@@ -152,9 +156,11 @@ int tsort_main(int argc UNUSED_PARAM, char **argv)
152 * - if any nodes are left, they form cycles. 156 * - if any nodes are left, they form cycles.
153 */ 157 */
154 cycles = 0; 158 cycles = 0;
159#if ENABLE_FEATURE_CLEAN_UP
160 max_len = G.nodes_len;
161#endif
155 while (G.nodes_len) { 162 while (G.nodes_len) {
156 struct node *n; 163 struct node *n;
157 unsigned i;
158 164
159 /* Search for first node with no incoming edges */ 165 /* Search for first node with no incoming edges */
160 for (i = 0; i < G.nodes_len; i++) { 166 for (i = 0; i < G.nodes_len; i++) {
@@ -173,16 +179,24 @@ int tsort_main(int argc UNUSED_PARAM, char **argv)
173 /* Remove the node (need no longer maintain sort) */ 179 /* Remove the node (need no longer maintain sort) */
174 n = G.nodes[i]; 180 n = G.nodes[i];
175 G.nodes[i] = G.nodes[--G.nodes_len]; 181 G.nodes[i] = G.nodes[--G.nodes_len];
182#if ENABLE_FEATURE_CLEAN_UP
183 /* Keep reference to removed node so it can be freed */
184 G.nodes[G.nodes_len] = n;
185#endif
176 186
177 /* And remove its outgoing edges */ 187 /* And remove its outgoing edges */
178 for (i = 0; i < n->out_count; i++) 188 for (i = 0; i < n->out_count; i++)
179 n->out[i]->in_count--; 189 n->out[i]->in_count--;
180 free(n->out);
181 190
182 puts(n->name); 191 puts(n->name);
183 free(n); 192 }
193#if ENABLE_FEATURE_CLEAN_UP
194 for (i = 0; i < max_len; i++) {
195 free(G.nodes[i]->out);
196 free(G.nodes[i]);
184 } 197 }
185 free(G.nodes); 198 free(G.nodes);
199#endif
186 200
187 fflush_stdout_and_exit(cycles ? 1 : 0); 201 fflush_stdout_and_exit(cycles ? 1 : 0);
188} 202}
diff --git a/shell/ash.c b/shell/ash.c
index 95f399b0b..634f4ce79 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -15860,7 +15860,7 @@ init(void)
15860 int import = 0; 15860 int import = 0;
15861#else 15861#else
15862 /* we will never free this */ 15862 /* we will never free this */
15863 basepf.next_to_pgetc = basepf.buf = ckmalloc(IBUFSIZ); 15863 basepf.next_to_pgetc = basepf.buf = ckzalloc(IBUFSIZ);
15864 basepf.linno = 1; 15864 basepf.linno = 1;
15865 15865
15866 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */ 15866 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */