std: fix memory leak on OutOfMemory error in math.big.int and math.big.rationa
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user