Commit 20574f5
prepare_{git,shell}_cmd: use argv_array
These functions transform an existing argv into one suitable
for exec-ing or spawning via git or a shell. We can use an
argv_array in each to avoid dealing with manual counting and
allocation.
This also makes the memory allocation more clear and fixes
some leaks. In prepare_shell_cmd, we would sometimes
allocate a new string with "$@" in it and sometimes not,
meaning the caller could not correctly free it. On the
non-Windows side, we are in a child process which will
exec() or exit() immediately, so the leak isn't a big deal.
On Windows, though, we use spawn() from the parent process,
and leak a string for each shell command we run. On top of
that, the Windows code did not free the allocated argv array
at all (but does for the prepare_git_cmd case!).
By switching both of these functions to write into an
argv_array, we can consistently free the result as
appropriate.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent 50a6c8e commit 20574f5
3 files changed
Lines changed: 39 additions & 53 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
| 111 | + | |
111 | 112 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
124 | 116 | | |
125 | 117 | | |
126 | 118 | | |
127 | | - | |
128 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
129 | 123 | | |
130 | 124 | | |
131 | | - | |
| 125 | + | |
132 | 126 | | |
133 | 127 | | |
134 | 128 | | |
135 | | - | |
| 129 | + | |
136 | 130 | | |
137 | 131 | | |
138 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | | - | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 163 | + | |
172 | 164 | | |
173 | 165 | | |
174 | 166 | | |
175 | 167 | | |
176 | | - | |
| 168 | + | |
177 | 169 | | |
178 | | - | |
| 170 | + | |
179 | 171 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 172 | + | |
190 | 173 | | |
191 | | - | |
192 | | - | |
193 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
194 | 183 | | |
195 | | - | |
| 184 | + | |
| 185 | + | |
196 | 186 | | |
197 | 187 | | |
198 | 188 | | |
199 | 189 | | |
200 | 190 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
205 | 196 | | |
206 | 197 | | |
207 | 198 | | |
| |||
455 | 446 | | |
456 | 447 | | |
457 | 448 | | |
| 449 | + | |
458 | 450 | | |
459 | 451 | | |
460 | 452 | | |
| |||
480 | 472 | | |
481 | 473 | | |
482 | 474 | | |
483 | | - | |
| 475 | + | |
484 | 476 | | |
485 | | - | |
| 477 | + | |
486 | 478 | | |
487 | 479 | | |
488 | 480 | | |
| |||
492 | 484 | | |
493 | 485 | | |
494 | 486 | | |
495 | | - | |
496 | | - | |
497 | | - | |
| 487 | + | |
498 | 488 | | |
499 | 489 | | |
500 | 490 | | |
| |||
0 commit comments