]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
guile: Avoid potentially missed reference.
authorLudovic Courtès <ludo@gnu.org>
Tue, 22 Dec 2020 09:30:43 +0000 (10:30 +0100)
committerLudovic Courtès <ludo@gnu.org>
Fri, 23 Apr 2021 21:23:46 +0000 (23:23 +0200)
There's one case where 'register_weak_reference' is called several times
on the same object, in 'set-certificate-credentials-x509-keys!', where
PRIVKEY could have been GC'd before CRED.

* guile/src/core.c (register_weak_reference): Add TO to the weak
references of FROM instead of overriding them.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
guile/src/core.c

index f61f4c47a272b612278994bfdf51906b4dcfc503..84e1009bee45f9699b3eac8a48295a3d8067653b 100644 (file)
@@ -1,5 +1,5 @@
 /* GnuTLS --- Guile bindings for GnuTLS.
-   Copyright (C) 2007-2014, 2016, 2019 Free Software Foundation, Inc.
+   Copyright (C) 2007-2014, 2016, 2019, 2020 Free Software Foundation, Inc.
 
    GnuTLS is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -96,11 +96,13 @@ const char scm_gnutls_array_error_message[] =
 static SCM weak_refs;
 
 /* Register a weak reference from @FROM to @TO, such that the lifetime of TO is
-   greater than or equal to that of FROM.  */
+   greater than or equal to that of FROM.  TO is added to the list of weak
+   references of FROM.  */
 static void
 register_weak_reference (SCM from, SCM to)
 {
-  scm_hashq_set_x (weak_refs, from, to);
+  SCM refs = scm_cons (to, scm_hashq_ref (weak_refs, from, SCM_EOL));
+  scm_hashq_set_x (weak_refs, from, refs);
 }
 
 \f