trace: Add active reference tracking

This WPA_TRACE=y additions allows components to register active references
to memory that has been provided to them as a pointer. If such an actively
referenced memory area is freed, tracer will report this as an error and
backtraces of both the invalid free and the location where this pointer
was marked referenced are shown.
This commit is contained in:
Jouni Malinen 2009-12-22 01:11:15 +02:00
parent a698d28415
commit a6ff0e0810
4 changed files with 106 additions and 3 deletions

View file

@ -19,6 +19,9 @@
#ifdef WPA_TRACE
static struct dl_list active_references =
{ &active_references, &active_references };
#ifdef WPA_TRACE_BFD
#include <bfd.h>
#include <demangle.h>
@ -255,4 +258,27 @@ void wpa_trace_show(const char *title)
wpa_trace_dump(title, &info);
}
void wpa_trace_add_ref_func(struct wpa_trace_ref *ref, const void *addr)
{
if (addr == NULL)
return;
ref->addr = addr;
wpa_trace_record(ref);
dl_list_add(&active_references, &ref->list);
}
void wpa_trace_check_ref(const void *addr)
{
struct wpa_trace_ref *ref;
dl_list_for_each(ref, &active_references, struct wpa_trace_ref, list) {
if (addr != ref->addr)
continue;
wpa_trace_show("Freeing referenced memory");
wpa_trace_dump("Reference registration", ref);
abort();
}
}
#endif /* WPA_TRACE */