我无法从我的 GArray 中检索值。
GArray * get_leakddata(struct memory* mem) {
struct leak_data {
char *file;
int line;
char *pointer;
size_t sz;
};
......
GArray * get_leakddata(struct memory* mem) {
GArray *leak_array = g_array_new(false, false,sizeof(struct leak_data));
g_hash_table_foreach(mem->metadata_hashtable,(GHFunc)get_leakdata_from_metadata, leak_array);
,struct leak_data *,3)->sz);
return leak_array;
}
void get_leakdata_from_metadata(char *key_address, struct metadata_record *metarec, GArray *leak_array) {
if(!get_isallocated(metarec))
return;
static int i=0;
struct leak_data * ld = (struct leak_data *) malloc(sizeof(struct leak_data));
ld->file = get_prev_file(metarec);
ld->line = get_prev_line(metarec);
ld->pointer = key_address;
ld->sz = get_metadata_recordsize(metarec);
printf("get_leakdata_from_metadata sz: %d\n",ld->sz);
g_array_append_val(leak_array,ld);
i++;
printf("get_leakdata_from_metadata 2: %d\n",g_array_index(leak_array,struct leak_data*,i)->sz);
}
打印出来:
get_leakdata_from_metadata sz: 12
get_leakdata_from_metadata 2: 1
最终我得到一个段错误