From db19041b9692dd9478f163964c486d696047fa2a Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 15 Sep 2023 09:05:53 -0700 Subject: [PATCH] fix memory leak when AWS_ENDPOINT_URL is used --- src/aws_http.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/aws_http.zig b/src/aws_http.zig index 41de07e..86777cb 100644 --- a/src/aws_http.zig +++ b/src/aws_http.zig @@ -304,8 +304,13 @@ fn getEnvironmentVariable(allocator: std.mem.Allocator, key: []const u8) !?[]con pub var endpoint_override: ?[]const u8 = null; fn endpointForRequest(allocator: std.mem.Allocator, service: []const u8, request: HttpRequest, options: Options) !EndPoint { - const environment_override = endpoint_override orelse try getEnvironmentVariable(allocator, "AWS_ENDPOINT_URL"); + if (endpoint_override) |override| { + const uri = try allocator.dupe(u8, override); + return endPointFromUri(allocator, uri, request.path); + } + const environment_override = try getEnvironmentVariable(allocator, "AWS_ENDPOINT_URL"); if (environment_override) |override| { + defer allocator.free(override); const uri = try allocator.dupe(u8, override); return endPointFromUri(allocator, uri, request.path); }