Skip to content

Commit

Permalink
perl reference counting of objects works fine, no dangers of double-d…
Browse files Browse the repository at this point in the history
…estruction

git-svn-id: svn://localhost/Crypt-GCrypt/trunk@82 c2f821fb-fd85-dc11-8383-000bcdcb7a8f
  • Loading branch information
dkg committed Jan 20, 2010
1 parent 0875dc4 commit 1bfa245
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Crypt/GCrypt/MPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ greater, negative if $other is greater.
=head2 copy()
Returns a new Crypt::GCrypt::MPI object, with the contents identical
to this one. This is better than using the assignment operator (=).
For example:
to this one. This is different from using the assignment operator
(=), which just makes two references to the same object. For example:
$b = new Crypt::GCrypt::MPI(15);
$a = $b; # DANGER! this may cause a double-free
# when $a and $b fall out of scope.
$a = $b;
$b->add(1); # $a points to the same object,
# so both $a and $b contain 16.
Expand Down
7 changes: 7 additions & 0 deletions t/20-mpi.t
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,10 @@ $y->sub($thirtysix);
ok(0 == $y->cmp(Crypt::GCrypt::MPI->new(65501)));
ok(0 == $x->cmp(Crypt::GCrypt::MPI->new(65537)));

{ my $a = $y;
$a->sub($thirtysix);
};

$y->sub($thirtysix);

ok(0 == $y->cmp(Crypt::GCrypt::MPI->new(65429)));

0 comments on commit 1bfa245

Please sign in to comment.