Skip to content

Commit 6bb0c0b

Browse files
committed
bugfix
1 parent 0ba4447 commit 6bb0c0b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
zig-out
2+
.zig-cache

Diff for: src/main.zig

+11-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn _main() !void {
5757
\\ z print stdout and stderr of z
5858
\\
5959
\\
60-
\\v20240720 https://github.com/txthinking/z
60+
\\v20240722 https://github.com/txthinking/z
6161
\\
6262
\\
6363
;
@@ -157,9 +157,12 @@ pub fn _main() !void {
157157
}
158158

159159
var l = try allocator.alloc([]u8, args.len - 1);
160+
var done: ?usize = null;
160161
defer {
161-
for (l) |v| {
162-
allocator.free(v);
162+
if (done) |i| {
163+
for (0..(i + 1)) |j| {
164+
allocator.free(l[j]);
165+
}
163166
}
164167
allocator.free(l);
165168
}
@@ -170,6 +173,7 @@ pub fn _main() !void {
170173
const b = try allocator.alloc(u8, v.len);
171174
@memcpy(b, v);
172175
l[i] = b;
176+
done = i;
173177
continue;
174178
}
175179
if (std.mem.startsWith(u8, v, ".") or std.mem.containsAtLeast(u8, v, 1, "/")) {
@@ -178,8 +182,10 @@ pub fn _main() !void {
178182
const b = try allocator.alloc(u8, b0.len);
179183
@memcpy(b, b0);
180184
l[i] = b;
185+
done = i;
181186
continue;
182187
}
188+
// std.process.Child does not find exec on given env now, so find it first
183189
var s1 = std.ArrayList(u8).init(allocator);
184190
defer s1.deinit();
185191
var s2 = std.ArrayList(u8).init(allocator);
@@ -199,11 +205,13 @@ pub fn _main() !void {
199205
const b = try allocator.alloc(u8, s1.items.len - 1);
200206
@memcpy(b, s1.items[0 .. s1.items.len - 1]);
201207
l[i] = b;
208+
done = i;
202209
continue;
203210
}
204211
const b = try allocator.alloc(u8, v.len);
205212
@memcpy(b, v);
206213
l[i] = b;
214+
done = i;
207215
}
208216

209217
var string = std.ArrayList(u8).init(allocator);

0 commit comments

Comments
 (0)