On Sat, Sep 03, 2022 at 08:42:53PM +0000, Job Snijders wrote:
> Found a small todo item in proc_parser() to free the entries in the auth
> and crl trees.

Reworked the diff to retain RB_GENERATE_STATIC() scope

OK?

Index: cert.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/cert.c,v
retrieving revision 1.88
diff -u -p -r1.88 cert.c
--- cert.c      3 Sep 2022 14:40:09 -0000       1.88
+++ cert.c      3 Sep 2022 20:58:55 -0000
@@ -978,6 +978,17 @@ authcmp(struct auth *a, struct auth *b)
 
 RB_GENERATE_STATIC(auth_tree, auth, entry, authcmp);
 
+void
+authtree_free(struct auth_tree *auths)
+{
+       struct auth     *auth, *tauth;
+
+       RB_FOREACH_SAFE(auth, auth_tree, auths, tauth) {
+               RB_REMOVE(auth_tree, auths, auth);
+               free(auth);
+       }
+}
+
 struct auth *
 auth_find(struct auth_tree *auths, const char *aki)
 {
Index: crl.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/crl.c,v
retrieving revision 1.15
diff -u -p -r1.15 crl.c
--- crl.c       21 Apr 2022 09:53:07 -0000      1.15
+++ crl.c       3 Sep 2022 20:58:55 -0000
@@ -118,3 +118,14 @@ crl_free(struct crl *crl)
        X509_CRL_free(crl->x509_crl);
        free(crl);
 }
+
+void
+crltree_free(struct crl_tree *crlt)
+{
+       struct crl      *crl, *tcrl;
+
+       RB_FOREACH_SAFE(crl, crl_tree, crlt, tcrl) {
+               RB_REMOVE(crl_tree, crlt, crl);
+               free(crl);
+       }
+}
Index: extern.h
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v
retrieving revision 1.155
diff -u -p -r1.155 extern.h
--- extern.h    3 Sep 2022 14:40:09 -0000       1.155
+++ extern.h    3 Sep 2022 20:58:58 -0000
@@ -511,6 +511,7 @@ struct tal  *tal_read(struct ibuf *);
 
 void            cert_buffer(struct ibuf *, const struct cert *);
 void            cert_free(struct cert *);
+void            authtree_free(struct auth_tree *);
 struct cert    *cert_parse_ee_cert(const char *, X509 *);
 struct cert    *cert_parse_pre(const char *, const unsigned char *, size_t);
 struct cert    *cert_parse(const char *, struct cert *);
@@ -556,6 +557,7 @@ struct crl  *crl_parse(const char *, cons
 struct crl     *crl_get(struct crl_tree *, const struct auth *);
 int             crl_insert(struct crl_tree *, struct crl *);
 void            crl_free(struct crl *);
+void            crltree_free(struct crl_tree *);
 
 /* Validation of our objects. */
 
Index: parser.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/parser.c,v
retrieving revision 1.76
diff -u -p -r1.76 parser.c
--- parser.c    3 Sep 2022 13:30:27 -0000       1.76
+++ parser.c    3 Sep 2022 20:58:59 -0000
@@ -744,7 +744,8 @@ proc_parser(int fd)
                entity_free(entp);
        }
 
-       /* XXX free auths and crl tree */
+       authtree_free(&auths);
+       crltree_free(&crlt);
 
        X509_STORE_CTX_free(ctx);
        msgbuf_clear(&msgq);

Reply via email to