Commit 01b9fa2c25
Changed files (2)
lib
std
math
lib/std/math/big/int.zig
@@ -2378,6 +2378,7 @@ pub const Managed = struct {
/// This is identical to an `init`, followed by a `set`.
pub fn initSet(allocator: Allocator, value: anytype) !Managed {
var s = try Managed.init(allocator);
+ errdefer s.deinit();
try s.set(value);
return s;
}
lib/std/math/big/rational.zig
@@ -30,8 +30,10 @@ pub const Rational = struct {
/// Create a new Rational. A small amount of memory will be allocated on initialization.
/// This will be 2 * Int.default_capacity.
pub fn init(a: Allocator) !Rational {
+ var p = try Int.init(a);
+ errdefer p.deinit();
return Rational{
- .p = try Int.init(a),
+ .p = p,
.q = try Int.initSet(a, 1),
};
}