clean up some memory issues maybe

This commit is contained in:
Jeffrey C. Ollie 2023-10-14 23:33:54 -05:00
parent f98d1b799b
commit 9e16bd8f62
Signed by: jeff
GPG key ID: 6F86035A6D97044E

View file

@ -127,7 +127,11 @@ pub fn main() !void {
var auth_header_buf: [256]u8 = undefined; var auth_header_buf: [256]u8 = undefined;
var auth_header = try std.fmt.bufPrint(&auth_header_buf, "Basic {s}", .{auth_encoded}); var auth_header = try std.fmt.bufPrint(&auth_header_buf, "Basic {s}", .{auth_encoded});
const uri = try std.Uri.parse(config.value.loki.url); var url_buf: [256]u8 = undefined;
@memcpy(url_buf, config.value.loki.url);
var url = url_buf[0..config.value.loki.url];
const uri = try std.Uri.parse(url);
var client = std.http.Client{ .allocator = allocator }; var client = std.http.Client{ .allocator = allocator };
defer client.deinit(); defer client.deinit();
@ -140,12 +144,22 @@ pub fn main() !void {
port = try std.fmt.bufPrint(&port_buf, "{d}", .{5201}); port = try std.fmt.bufPrint(&port_buf, "{d}", .{5201});
} }
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var path: []u8 = undefined;
if (config.value.iperf3.path) |p| {
@memcpy(path_buf, p);
path = path_buf[0..p.len];
} else {
@memcpy(path_buf, "iperf3");
path = path_buf[0..6];
}
while (true) { while (true) {
iperf3_log.info("waiting for connection", .{}); iperf3_log.info("waiting for connection", .{});
// try stderr_bw.flush();
var c = std.process.Child.init( var c = std.process.Child.init(
&[_][]const u8{ &[_][]const u8{
if (config.value.iperf3.path) |path| path else "iperf3", path,
"--server", "--server",
"--port", "--port",
port, port,
@ -208,10 +222,6 @@ pub fn main() !void {
); );
defer data.deinit(); defer data.deinit();
// try stderr.writeAll(data.items);
// try stderr.writeAll("\n");
// try stderr_bw.flush();
var content_length_buf: [16]u8 = undefined; var content_length_buf: [16]u8 = undefined;
var content_length = try std.fmt.bufPrint( var content_length = try std.fmt.bufPrint(
&content_length_buf, &content_length_buf,
@ -226,6 +236,8 @@ pub fn main() !void {
try headers.append("Content-Length", content_length); try headers.append("Content-Length", content_length);
var req = try client.request(.POST, uri, headers, .{}); var req = try client.request(.POST, uri, headers, .{});
defer req.deinit();
try req.start(); try req.start();
try req.writeAll(data.items); try req.writeAll(data.items);
try req.finish(); try req.finish();