Browse Source

Fix coverity issues (#18892)

* Get lock before check
Ignore return code

* In case timeout is not given assume 1000ms
Stelios Fragkakis 4 months ago
parent
commit
93ff15f182

+ 1 - 1
src/database/sqlite/sqlite_metadata.c

@@ -2367,7 +2367,7 @@ done:
 
 void cleanup_agent_event_log(void)
 {
-    db_execute(db_meta, "DELETE FROM agent_event_log WHERE date_created < UNIXEPOCH() - 30 * 86400");
+    (void) db_execute(db_meta, "DELETE FROM agent_event_log WHERE date_created < UNIXEPOCH() - 30 * 86400");
 }
 
 #define SQL_GET_AGENT_EVENT_TYPE_MEDIAN                                                                                \

+ 2 - 3
src/exporting/prometheus/prometheus.c

@@ -88,9 +88,8 @@ static netdata_mutex_t prometheus_server_root_mutex = NETDATA_MUTEX_INITIALIZER;
  */
 void prometheus_clean_server_root()
 {
+    netdata_mutex_lock(&prometheus_server_root_mutex);
     if (prometheus_server_root) {
-        netdata_mutex_lock(&prometheus_server_root_mutex);
-
         struct prometheus_server *ps;
         for (ps = prometheus_server_root; ps; ) {
             struct prometheus_server *current = ps;
@@ -101,8 +100,8 @@ void prometheus_clean_server_root()
             freez(current);
         }
         prometheus_server_root = NULL;
-        netdata_mutex_unlock(&prometheus_server_root_mutex);
     }
+    netdata_mutex_unlock(&prometheus_server_root_mutex);
 }
 
 /**

+ 4 - 3
src/libnetdata/dictionary/dictionary.c

@@ -318,10 +318,11 @@ static void dictionary_queue_for_destruction(DICTIONARY *dict) {
 }
 
 void cleanup_destroyed_dictionaries(void) {
-    if(!dictionaries_waiting_to_be_destroyed)
-        return;
-
     netdata_mutex_lock(&dictionaries_waiting_to_be_destroyed_mutex);
+    if (!dictionaries_waiting_to_be_destroyed) {
+        netdata_mutex_unlock(&dictionaries_waiting_to_be_destroyed_mutex);
+        return;
+    }
 
     DICTIONARY *dict, *last = NULL, *next = NULL;
     for(dict = dictionaries_waiting_to_be_destroyed; dict ; dict = next) {

+ 1 - 1
src/libnetdata/socket/socket.c

@@ -953,7 +953,7 @@ int connect_to_this_ip46(
                            hostBfr, servBfr);
 
                     // Convert 'struct timeval' to milliseconds for poll():
-                    int timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
+                    int timeout_ms = timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : 1000;
 
                     switch(wait_on_socket_or_cancel_with_timeout(
                         NULL,