From: Nathan S. Evans Date: Wed, 10 Nov 2010 12:39:32 +0000 (+0000) Subject: codesonar fixes X-Git-Tag: initial-import-from-subversion-38251~19773 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e1e25c0c4828c2d8c93f4ede4191de3895592aab;p=oweals%2Fgnunet.git codesonar fixes --- diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 68e662269..285ec1a30 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -555,7 +555,7 @@ void GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) { struct PendingMessage *pm; - + GNUNET_assert(handle != NULL); GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size(handle->active_requests)); if (handle->th != NULL) { diff --git a/src/dht/dht_api_get_put.c b/src/dht/dht_api_get_put.c index c6cd2c57a..98ee8d822 100644 --- a/src/dht/dht_api_get_put.c +++ b/src/dht/dht_api_get_put.c @@ -247,6 +247,9 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, * Stop async DHT-get. * * @param get_handle handle to the GET operation to stop + * + * On return get_handle will no longer be valid, caller + * must not use again!!! */ void GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 1e238c620..39e5eec72 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c @@ -414,8 +414,6 @@ static struct GNUNET_TIME_Relative malicious_put_frequency; static unsigned long long settle_time; -static unsigned long long trial_to_run; - static struct GNUNET_DHTLOG_Handle *dhtlog_handle; static unsigned long long trialuid; @@ -466,7 +464,7 @@ static unsigned int *churn_array; /** * Hash map of stats contexts. */ -struct GNUNET_CONTAINER_MultiHashMap *stats_map; +static struct GNUNET_CONTAINER_MultiHashMap *stats_map; /** * LL of malicious settings. @@ -507,7 +505,7 @@ static struct GNUNET_TESTING_PeerGroup *pg; /** * Global config handle. */ -const struct GNUNET_CONFIGURATION_Handle *config; +static const struct GNUNET_CONFIGURATION_Handle *config; /** * Total number of peers to run, set based on config file. @@ -693,8 +691,8 @@ reset_meter(struct ProgressMeter *meter) static void free_meter(struct ProgressMeter *meter) { - GNUNET_free_non_null(meter->startup_string); - GNUNET_free_non_null(meter); + GNUNET_free_non_null (meter->startup_string); + GNUNET_free (meter); } /** @@ -1125,6 +1123,7 @@ static void add_new_connection(struct FindPeerContext *find_peer_context, if (GNUNET_CONTAINER_multihashmap_contains(find_peer_context->peer_hash, &first->hashPubKey)) { first_count = GNUNET_CONTAINER_multihashmap_get(find_peer_context->peer_hash, &first->hashPubKey); + GNUNET_assert(first_count != NULL); first_count->count++; GNUNET_CONTAINER_heap_update_cost(find_peer_context->peer_min_heap, first_count->heap_node, first_count->count); } @@ -1140,6 +1139,7 @@ static void add_new_connection(struct FindPeerContext *find_peer_context, if (GNUNET_CONTAINER_multihashmap_contains(find_peer_context->peer_hash, &second->hashPubKey)) { second_count = GNUNET_CONTAINER_multihashmap_get(find_peer_context->peer_hash, &second->hashPubKey); + GNUNET_assert(second_count != NULL); second_count->count++; GNUNET_CONTAINER_heap_update_cost(find_peer_context->peer_min_heap, second_count->heap_node, second_count->count); } @@ -1179,10 +1179,12 @@ static int iterate_min_heap_peers (void *cls, if (cost == 0) { d1 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id); + GNUNET_assert(d1 != NULL); d2 = d1; while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_daemon_running(d2))) { d2 = GNUNET_TESTING_daemon_get(pg, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); + GNUNET_assert(d2 != NULL); } /** Just try to connect the peers, don't worry about callbacks, etc. **/ @@ -1233,7 +1235,7 @@ count_peers_churn_cb (void *cls, GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer count finished (%u connections)\n", find_peer_context->current_peers); peer_count = GNUNET_CONTAINER_heap_peek(find_peer_context->peer_min_heap); - + GNUNET_assert(peer_count != NULL); /* WAIT. When peers are churned they will come back with their peers (at least in peerinfo), because the HOSTS file doesn't likely get removed. CRAP. */ /* NO they won't, because we have disabled peerinfo writing to disk (remember?) so we WILL have to give them new connections */ /* Best course of action: have DHT automatically try to add peers from peerinfo on startup. This way IF peerinfo writes to file @@ -1363,6 +1365,7 @@ schedule_churn_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_Task test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer)); /* If we have sent requests, choose peers with a low number of connections to send requests from */ peer_count = GNUNET_CONTAINER_heap_remove_root(find_peer_ctx->peer_min_heap); + GNUNET_assert(peer_count != NULL); GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending find peer request from peer with %u connections\n", peer_count->count); GNUNET_CONTAINER_multihashmap_remove(find_peer_ctx->peer_hash, &peer_count->peer_id.hashPubKey, peer_count); test_find_peer->daemon = GNUNET_TESTING_daemon_get_by_id(pg, &peer_count->peer_id); @@ -1902,10 +1905,10 @@ count_peers_cb (void *cls, connection_estimate(num_peers, DEFAULT_BUCKET_SIZE), 2 * connection_estimate(num_peers, DEFAULT_BUCKET_SIZE)); - if ((find_peer_context->last_sent > 8) && - (find_peer_context->current_peers - find_peer_context->previous_peers > FIND_PEER_THRESHOLD) && + if ((find_peer_context->last_sent < 8) || + ((find_peer_context->current_peers - find_peer_context->previous_peers > FIND_PEER_THRESHOLD) && (find_peer_context->current_peers < 2 * connection_estimate(num_peers, DEFAULT_BUCKET_SIZE)) && - (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).rel_value > 0)) + (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).rel_value > 0))) { GNUNET_SCHEDULER_add_now(&schedule_find_peer_requests, find_peer_context); } @@ -2469,6 +2472,7 @@ run (void *cls, char *hostfile; float topology_probability; unsigned long long temp_config_number; + unsigned long long trial_to_run; int stop_closest; int stop_found; int strict_kademlia; @@ -2480,6 +2484,7 @@ run (void *cls, int ret; int line_number; + config = cfg; rounds_finished = 0; memset(&trial_info, 0, sizeof(struct GNUNET_DHTLOG_TrialInfo)); @@ -2533,6 +2538,8 @@ run (void *cls, if (GNUNET_OK != GNUNET_DISK_file_test (churn_filename)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error reading churn file!\n"); + GNUNET_free_non_null(trialmessage); + GNUNET_free(churn_filename); return; } if ((0 != STAT (churn_filename, &frstat)) || (frstat.st_size == 0)) @@ -2571,10 +2578,10 @@ run (void *cls, churn_data[count] = '\0'; if (1 != sscanf(buf, "%u", &churn_rounds)) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to read number of rounds from %s, ending test!\n", churn_filename); - GNUNET_free_non_null(trialmessage); - GNUNET_free(churn_filename); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to read number of rounds from churn file, ending test!\n"); ret = 4200; + GNUNET_free_non_null(trialmessage); + GNUNET_free_non_null(churn_data); return; } GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read %u rounds from churn file\n", churn_rounds); diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index d74309e21..ae57c0ea7 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -1672,7 +1672,7 @@ static void forward_message (const struct GNUNET_MessageHeader *msg, size_t psize; increment_stats(STAT_ROUTE_FORWARDS); - + GNUNET_assert(peer != NULL); if ((msg_ctx->closest != GNUNET_YES) && (peer == find_closest_peer(&msg_ctx->key))) increment_stats(STAT_ROUTE_FORWARDS_CLOSEST); @@ -2434,6 +2434,7 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, else /* We don't want this peer! */ { route_message (find_msg, message_context); + GNUNET_free (other_hello); return; } #endif @@ -2512,6 +2513,7 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg, } else { + GNUNET_free(recent_hash); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received duplicate find peer request too soon!\n"); } @@ -3912,7 +3914,6 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) get_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_GET); get_message.type = htonl(GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE); memset(&message_context, 0, sizeof(struct DHT_MessageContext)); - message_context.client = NULL; random_key = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1); GNUNET_CRYPTO_hash(&random_key, sizeof(uint32_t), &key); memcpy(&message_context.key, &key, sizeof(GNUNET_HashCode)); @@ -4539,6 +4540,7 @@ void handle_core_disconnect (void *cls, increment_stats(STAT_DISCONNECTS); GNUNET_assert(GNUNET_CONTAINER_multihashmap_contains(all_known_peers, &peer->hashPubKey)); to_remove = GNUNET_CONTAINER_multihashmap_get(all_known_peers, &peer->hashPubKey); + GNUNET_assert (to_remove != NULL); GNUNET_assert(0 == memcmp(peer, &to_remove->id, sizeof(struct GNUNET_PeerIdentity))); current_bucket = find_current_bucket(&to_remove->id.hashPubKey); delete_peer(to_remove, current_bucket); diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c index b31a41f4c..127db015d 100644 --- a/src/dht/plugin_dhtlog_mysql.c +++ b/src/dht/plugin_dhtlog_mysql.c @@ -1356,8 +1356,6 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, if (from_node != NULL) get_node_uid (&from_uid, &from_node->hashPubKey); - else - from_uid = 0; if (to_node != NULL) get_node_uid (&to_uid, &to_node->hashPubKey); @@ -1456,9 +1454,8 @@ update_current_topology (unsigned int connections) } if (ret > 0) return GNUNET_OK; - else - return GNUNET_SYSERR; - return GNUNET_OK; + return GNUNET_SYSERR; + } /* @@ -1487,9 +1484,7 @@ add_topology (int num_connections) } if (ret > 0) return GNUNET_OK; - else - return GNUNET_SYSERR; - return GNUNET_OK; + return GNUNET_SYSERR; } /* @@ -1535,9 +1530,7 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU } if (ret > 0) return GNUNET_OK; - else - return GNUNET_SYSERR; - return GNUNET_OK; + return GNUNET_SYSERR; } diff --git a/src/dht/plugin_dhtlog_mysql_dump.c b/src/dht/plugin_dhtlog_mysql_dump.c index f8a2811b1..6b6133068 100644 --- a/src/dht/plugin_dhtlog_mysql_dump.c +++ b/src/dht/plugin_dhtlog_mysql_dump.c @@ -490,10 +490,7 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node) if (outfile == NULL) return GNUNET_SYSERR; - if (node != NULL) - ret = fprintf(outfile, "set @node = \"%s\";\n", GNUNET_h2s_full(&node->hashPubKey)); - else - return GNUNET_SYSERR; + ret = fprintf(outfile, "set @node = \"%s\";\n", GNUNET_h2s_full(&node->hashPubKey)); if (ret < 0) return GNUNET_SYSERR;