I am currently debugging a C code. This is basically a client from a data collection platform and I was getting weird bugs reading from a linked list. The problem basically is that the "next" pointer of the last item changes in some unknown point from NULL to 0xFFFFFFFFF. Then I tried to compile my library with address sanitizer in order to find where the bug bug could be and the bug disappeared, or it would be better to say that the bug is currently hidden. Is it possible? How can Asan library affect to the code to make not crash? thanks in advance.
EDIT: Sorry for the poor description, I will try to go deeper. I have been debugging the code and I have found where the problem is. It is in a parsing function from a json configuration file (I use jansson library for this purpose). The json format is like this:
{
...
"version": {
"software": "0.2",
"firmware": "0.2"
},
"system": ["system_A", "system_B"],
...
"internal_devices : [
{
...
"version": {
"software": "0.2",
"firmware": "0.2"
},
"system": ["system_B"],
...
},
...
"version" : {
"software": "0.2",
"firmware": "0.2"
},
"system": ["system_A"],
...
}
]
}
}
And I have a struct like this to store this data
typedef struct XXX_NODE {
mqtt_client_t * client;
XXX_Device devices[XXX_MAX_DEVICES];
size_t num_devices;
XXX_operation_mode mode;
pthread_mutex_t callback_lock;
pthread_mutex_t registration_lock;
pthread_cond_t registration_condition;
}XXX_NODE;
typedef struct XXX_id {
...
struct XXX_parent parent_unit;
// char parent_fin[64];
int internal_level_tree;
XXX_version version;
List XXX_systems;
List extended_topics;
bool registered;
}XXX_id;
The real problem is in List XXX_systems. I have a List per device, and I can have several devices in the same struct, where the first element (in the XXX_Device devices array) is the main unit. And it is in this device where I loose information. The parsing function looks work properly. At the end of the function, the struct has rights values, but when I free json "objects", I loose the reference of the XXX_systems->next
, but the weird thing is if I don't free some json "objects", everything works...
So, in this case, I loose information:
json_decref(internal_list);
json_decref(unit);
json_decref(root);
return 0;
But if I comment json_decref like this
json_decref(internal_list);
//json_decref(unit);
json_decref(root);
return 0;
everything works...