]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Fix leaks due to bad struct release and wrong lock usage
authorpcarana <pc.moreno2099@gmail.com>
Wed, 23 Sep 2020 17:02:45 +0000 (12:02 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Wed, 23 Sep 2020 17:02:45 +0000 (12:02 -0500)
+Also add missing parenthesis at logging docs, and fix lock usage at RRDP DB (db_rrdp_reset_visited_tals).

docs/logging.md
src/reqs_errors.c
src/rrdp/db/db_rrdp.c
src/rsync/rsync.c

index 8b28d5dc7312fb3df8dc975f5c80e018e3f591f3..bac5d34b63f10bdd78381588109952ebd06cfaee 100644 (file)
@@ -51,7 +51,7 @@ The following messages are included at the operation logs:
 - Out of memory errors.
 - Read/write errors on local files.
 - Persistent communication errors with RPKI repositories (see [`--stale-repository-period`](usage.html#--stale-repository-period)).
-- Start and end of a validation cycle, including: number of valid Prefixes and Router Keys, current RTR serial number (only when [`--mode=server`](usage.html#--mode), and real execution time.
+- Start and end of a validation cycle, including: number of valid Prefixes and Router Keys, current RTR serial number (only when [`--mode=server`](usage.html#--mode)), and real execution time.
 - Programming errors (of course, those that could be expected due to an API misuse).
 
 ### Validation
index 73df8194d65f1e4f6f334cd0792814a679322b62..31c528d4a65e7f20ecfffbfe1c41684ec7abf0bd 100644 (file)
@@ -115,13 +115,15 @@ reqs_errors_cleanup(void)
 }
 
 static struct error_uri *
-find_error_uri(char const *search)
+find_error_uri(char const *search, bool lock)
 {
        struct error_uri *found;
 
-       rwlock_read_lock(&db_lock);
+       if (lock)
+               rwlock_read_lock(&db_lock);
        HASH_FIND_STR(err_uris_db, search, found);
-       rwlock_unlock(&db_lock);
+       if (lock)
+               rwlock_unlock(&db_lock);
 
        return found;
 }
@@ -136,7 +138,7 @@ set_working_repo(struct error_uri *err_uri)
        if (work_uri == NULL)
                return;
 
-       ref = find_error_uri(work_uri);
+       ref = find_error_uri(work_uri, true);
        if (ref == NULL)
                return;
 
@@ -151,7 +153,7 @@ reqs_errors_add_uri(char const *uri)
        int error;
 
        /* Don't overwrite if it already exists */
-       found_uri = find_error_uri(uri);
+       found_uri = find_error_uri(uri, true);
        if (found_uri != NULL)
                return 0;
 
@@ -182,16 +184,23 @@ void
 reqs_errors_rem_uri(char const *uri)
 {
        struct error_uri *found_uri;
+       struct error_uri *tmp;
        char *ref_uri;
 
-       found_uri = find_error_uri(uri);
-       if (found_uri == NULL)
+       rwlock_write_lock(&db_lock);
+       found_uri = find_error_uri(uri, false);
+       if (found_uri == NULL) {
+               rwlock_unlock(&db_lock);
                return;
+       }
 
-       while (found_uri->uri_related != NULL)
-               found_uri = find_error_uri(found_uri->uri_related);
+       while (found_uri->uri_related != NULL) {
+               tmp = find_error_uri(found_uri->uri_related, false);
+               if (tmp == NULL)
+                       break;
+               found_uri = tmp;
+       }
 
-       rwlock_write_lock(&db_lock);
        do {
                ref_uri = found_uri->ref_by;
                HASH_DELETE(hh, err_uris_db, found_uri);
@@ -199,6 +208,8 @@ reqs_errors_rem_uri(char const *uri)
                if (ref_uri == NULL)
                        break;
                HASH_FIND_STR(err_uris_db, ref_uri, found_uri);
+               if (found_uri == NULL)
+                       break;
        } while (true);
        rwlock_unlock(&db_lock);
 }
@@ -241,7 +252,7 @@ reqs_errors_log_uri(char const *uri)
        if (config_period == 0)
                return true;
 
-       node = find_error_uri(uri);
+       node = find_error_uri(uri, true);
        if (node == NULL)
                return false;
 
index b6e0363bfaee6c8c5888b8a55a2919aabf8a0b27..7487cabffbc9654ae39e3b998bf36927752a8b4d 100644 (file)
@@ -166,7 +166,7 @@ db_rrdp_reset_visited_tals(void)
 {
        struct tal_elem *found;
 
-       rwlock_read_lock(&lock);
+       rwlock_write_lock(&lock);
        SLIST_FOREACH(found, &db.tals, next)
                found->visited = false;
 
index 6c7f9c55ba3a05583bfbd7b620248a2cdea2f369..786e3b3241115897d85ba5671c5ad1ebcbde9244 100644 (file)
@@ -522,7 +522,7 @@ ancestor_error(char const *error_uri, void *arg)
 
        error = is_descendant(req_err_uri, search) ? EEXIST : 0;
 
-       free(req_err_uri);
+       uri_refput(req_err_uri);
        return error;
 }