Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

perl reference counting of objects works fine, no dangers of double-d…

…estruction

git-svn-id: svn://localhost/Crypt-GCrypt/trunk@82 c2f821fb-fd85-dc11-8383-000bcdcb7a8f
  • Loading branch information...
commit 1bfa2454f667e2f97def6b22e8b4a31f1ec56a8d 1 parent 0875dc4
dkg authored
Showing with 10 additions and 4 deletions.
  1. +3 −4 lib/Crypt/GCrypt/MPI.pm
  2. +7 −0 t/20-mpi.t
View
7 lib/Crypt/GCrypt/MPI.pm
@@ -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.
View
7 t/20-mpi.t
@@ -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)));
Please sign in to comment.
Something went wrong with that request. Please try again.