後に初期化されていない値(複数可)に依存します。私は途中で何か間違ったのsupsectedC(Linuxの) - valgrindの:条件付きジャンプや移動は、私は次の出力だ私のプログラムにvalgrindのを実行した後のrealloc
==17731== Thread 2:
==17731== Conditional jump or move depends on uninitialised value(s)
==17731== at 0x401CD8: poll_existing_connections (connmgr.c:112)
==17731== by 0x401ACD: connmgr_listen (connmgr.c:69)
==17731== by 0x40161A: connmgr (main.c:148)
==17731== by 0x5545609: start_thread (in /usr/lib64/libpthread-2.22.so)
==17731== Uninitialised value was created by a heap allocation
==17731== at 0x4C2AB8B: realloc (vg_replace_malloc.c:785)
==17731== by 0x401B64: poll_new_connection (connmgr.c:85)
==17731== by 0x401AB9: connmgr_listen (connmgr.c:68)
==17731== by 0x40161A: connmgr (main.c:148)
==17731== by 0x5545609: start_thread (in /usr/lib64/libpthread-2.22.so)
==17731==
をI reallocを使用します。私はグーグルを始めて、他のユーザーのために働いていたソリューションを試しましたが、どちらのソリューションも私のために働いていませんでした。 私は別の方法(新しいメモリをmallocして新しい値で配列の古い値をコピー)を試みましたが、valgrindで同じ種類のエラーが発生しました。
何が間違っているかについてのご意見はありますか?
私のコード(connmgr.c:112):
sensor_conn_t * sensor_conn = dpl_get_element_at_index(sensor_sockets, i);
poll_action = poll_list[i].revents == POLLIN;
if(poll_action == POLLIN) {
//The sensor sent some data
read_data(sensor_conn, i, buffer);
} else {
//No data received from the sensor
check_timeout();
}
私のコード(connmgr.c:85):あなたはのreallocを呼び出しているが、あなたは内容を初期化していない
//Add the new connection to an array so that it is pollable
struct pollfd * new_poll_list = realloc(poll_list, (nb_connections + 1) * sizeof(struct pollfd));
assert(new_poll_list != NULL);
poll_list = new_poll_list;
tcp_get_sd(client, &poll_list[nb_connections].fd);
poll_list[nb_connections].events = POLLIN;
'poll_list'を大きくしましたが、どこで新しい要素を初期化しますか? 'poll_list [i] .revents'はどこで初期化されていますか? – Schwern
@Schwern私は、これらの行ですべてを初期化したことを教えました:tcp_get_sd(client、&poll_list [nb_connections] .fd); poll_list [nb_connections] .events = POLLIN; 私はpoll_list [i]を初期化するのを忘れました.revents ありがとう、これは私の問題を解決しました。 – TrueStory