我正在用C编程,我无法摆脱valgrind错误。
char* s; // this one has some value...
GHashTable* hash = g_hash_table_new(g_str_hash, g_str_equal);
char** lineSplit = g_strsplit(s, "\n", -1);
// temp is in a loop, but for this example I only insert one (still error)
char** temp = g_strsplit(lineSplit[0], " ", 2);
g_hash_table_insert(hash, temp[0], temp[1]); // yes the temp length > 1
g_strfreev(temp);
g_strfreev(lineSplit);
// now, valgrind won't give me an error so far
// but when I call lookup, then valgrind finds an error in
// inserting temp[0] values
gpointer t = g_hash_table_lookup(hash, "some value"); // don't have to free
if(!strcmp(t, "bla")) printf("yihaa");
g_hash_table_destroy(hash);
Valgrind错误是:
读取大小为1。
(在循环中发生4次)
错误摘要:来自4个上下文的4个错误(被抑制:0从0开始)
我正在运行Valgrind:
env G_DEBUG = gc-friendly G_SLICE = always-malloc valgrind --leak-check = full --track-originins = yes ./program
提前致谢! - 希望你能帮帮我。