X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_ovs.c;h=6fe6fe764e439a6d0fcdd014b5cadffc023f82df;hb=fc7ccf8381117058e9c6bef155cc3fe6d6d9ac1c;hp=57629a01a15f13771280d5a4873999783c6974b0;hpb=61a4ed99b1a5b6d371bb745933d0efc5dff9505c;p=collectd.git diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 57629a01..6fe6fe76 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -191,7 +191,7 @@ struct ovs_db_s { }; /* Global variables */ -static uint64_t ovs_uid = 0; +static uint64_t ovs_uid; static pthread_mutex_t ovs_uid_mutex = PTHREAD_MUTEX_INITIALIZER; /* Post an event to event thread. @@ -609,9 +609,8 @@ static int ovs_db_json_data_process(ovs_db_t *pdb, const char *data, /* Allocate JSON reader instance */ static ovs_json_reader_t *ovs_json_reader_alloc() { - ovs_json_reader_t *jreader = NULL; - - if ((jreader = calloc(sizeof(ovs_json_reader_t), 1)) == NULL) + ovs_json_reader_t *jreader = calloc(1, sizeof(*jreader)); + if (jreader == NULL) return NULL; return jreader; @@ -720,13 +719,17 @@ static void ovs_db_reconnect(ovs_db_t *pdb) { if (pdb->unix_path[0] != '\0') { /* use UNIX socket instead of INET address */ node_info = pdb->unix_path; - result = calloc(1, sizeof(struct addrinfo)); - struct sockaddr_un *sa_unix = calloc(1, sizeof(struct sockaddr_un)); - if (result == NULL || sa_unix == NULL) { - sfree(result); - sfree(sa_unix); + + struct sockaddr_un *sa_unix = calloc(1, sizeof(*sa_unix)); + if (sa_unix == NULL) + return; + + result = calloc(1, sizeof(*result)); + if (result == NULL) { + free(sa_unix); return; } + result->ai_family = AF_UNIX; result->ai_socktype = SOCK_STREAM; result->ai_addrlen = sizeof(*sa_unix); @@ -1051,6 +1054,8 @@ ovs_db_t *ovs_db_init(const char *node, const char *service, ret = ovs_db_destroy(pdb); if (ret > 0) goto failure; + else + return NULL; } /* init polling thread */ @@ -1059,6 +1064,8 @@ ovs_db_t *ovs_db_init(const char *node, const char *service, if (ret > 0) { ovs_db_event_thread_data_destroy(pdb); goto failure; + } else { + return NULL; } } return pdb; @@ -1117,7 +1124,7 @@ int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params, if (cb) { /* register result callback */ - if ((new_cb = calloc(1, sizeof(ovs_callback_t))) == NULL) + if ((new_cb = calloc(1, sizeof(*new_cb))) == NULL) goto yajl_gen_failure; /* add new callback to front */ @@ -1175,7 +1182,7 @@ int ovs_db_table_cb_register(ovs_db_t *pdb, const char *tb_name, return -1; /* allocate new update callback */ - if ((new_cb = calloc(1, sizeof(ovs_callback_t))) == NULL) + if ((new_cb = calloc(1, sizeof(*new_cb))) == NULL) return -1; /* init YAJL generator */