Skip to content

Commit 661849f

Browse files
authored
Fix ml_z_remove w.r.t. GC rules (#108)
`Field(...) = allocating_expression` can misbehave if the address of the left hand side is computed before the allocating expression is evaluated and triggers a GC. This pull request simply goes through a temporary variable.
1 parent c17e635 commit 661849f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

caml_z.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,15 +3049,16 @@ CAMLprim value ml_z_kronecker(value a, value b)
30493049
CAMLprim value ml_z_remove(value a, value b)
30503050
{
30513051
CAMLparam2(a,b);
3052-
CAMLlocal1(r);
3052+
CAMLlocal2(r,tmp);
30533053
mpz_t ma, mb, mr;
30543054
int i;
30553055
ml_z_mpz_init_set_z(ma, a);
30563056
ml_z_mpz_init_set_z(mb, b);
30573057
mpz_init(mr);
30583058
i = mpz_remove(mr, ma, mb);
3059+
tmp = ml_z_from_mpz(mr);
30593060
r = caml_alloc_small(2, 0);
3060-
Field(r,0) = ml_z_from_mpz(mr);
3061+
Field(r,0) = tmp;
30613062
Field(r,1) = Val_int(i);
30623063
mpz_clear(ma);
30633064
mpz_clear(mb);

0 commit comments

Comments
 (0)