authorgravatar for gethwilliams@googlemail.comGethDW <gethwilliams@googlemail.com> 2022-10-11 18:12:03+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-10-11 20:12:03+03:00
log01b9fa2c2574bd02937ce40525e94026c3acd551
tree9dc57db34c1101496eb8353ffbdb00e9db115507
parenta72b584c765e0b714e40b55b43971d4b0d2ad8dd
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std: fix memory leak on OutOfMemory error in math.big.int and math.big.rationa


2 files changed, 4 insertions(+), 1 deletions(-)

lib/std/math/big/int.zig+1
......@@ -2378,6 +2378,7 @@ pub const Managed = struct {
23782378 /// This is identical to an `init`, followed by a `set`.
23792379 pub fn initSet(allocator: Allocator, value: anytype) !Managed {
23802380 var s = try Managed.init(allocator);
2381 errdefer s.deinit();
23812382 try s.set(value);
23822383 return s;
23832384 }
lib/std/math/big/rational.zig+3-1
......@@ -30,8 +30,10 @@ pub const Rational = struct {
3030 /// Create a new Rational. A small amount of memory will be allocated on initialization.
3131 /// This will be 2 * Int.default_capacity.
3232 pub fn init(a: Allocator) !Rational {
33 var p = try Int.init(a);
34 errdefer p.deinit();
3335 return Rational{
34 .p = try Int.init(a),
36 .p = p,
3537 .q = try Int.initSet(a, 1),
3638 };
3739 }