Compare commits
No commits in common. "3169bc0458610fd92aeb2330b112b4842cf2985b" and "8f1bf7a5a82d1b70e800a08e9d231caf9031f891" have entirely different histories.
3169bc0458
...
8f1bf7a5a8
4 changed files with 10 additions and 38 deletions
|
@ -1,10 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
## Version 2.3
|
||||
|
||||
Added ids to each chunk of allocated memory to make it easier to keep track of
|
||||
which allocated memory refers to which unfreed memory.
|
||||
|
||||
## Version 2.2
|
||||
|
||||
Minor refactoring: remove unused constexpr declarations in header.
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
namespace SC_AM_Internal {
|
||||
Stats *stats = nullptr;
|
||||
int is_env_status = 0;
|
||||
unsigned long long Malloced::count = 0;
|
||||
|
||||
Stats *get_init_stats() {
|
||||
Stats *stats = reinterpret_cast<SC_AM_Internal::Stats*>(
|
||||
|
@ -26,8 +25,8 @@ namespace SC_AM_Internal {
|
|||
void *(*real_calloc)(std::size_t, std::size_t) = nullptr;
|
||||
void (*real_free)(void*) = nullptr;
|
||||
|
||||
Malloced::Malloced() : address(nullptr), size(0), id(0) {}
|
||||
Malloced::Malloced(void *address, std::size_t size) : address(address), size(size), id(0) {}
|
||||
Malloced::Malloced() : address(nullptr), size(0) {}
|
||||
Malloced::Malloced(void *address, std::size_t size) : address(address), size(size) {}
|
||||
|
||||
void ListNode::add_to_list(ListNode *tail, Malloced *data) {
|
||||
ListNode *new_node = reinterpret_cast<ListNode*>(real_malloc(sizeof(ListNode)));
|
||||
|
@ -44,9 +43,6 @@ namespace SC_AM_Internal {
|
|||
while (node != nullptr) {
|
||||
node = node->next;
|
||||
if (node->data && node->data->address == ptr) {
|
||||
if (is_env_status == ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
||||
std::clog << " id: " << node->data->id << std::endl;
|
||||
}
|
||||
node->prev->next = node->next;
|
||||
node->next->prev = node->prev;
|
||||
real_free(node->data);
|
||||
|
@ -96,10 +92,6 @@ namespace SC_AM_Internal {
|
|||
Malloced *data = reinterpret_cast<Malloced*>(real_malloc(sizeof(Malloced)));
|
||||
data->address = address;
|
||||
data->size = size;
|
||||
data->id = data->count++;
|
||||
if (is_env_status == ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
||||
std::clog << " id: " << data->id << std::endl;
|
||||
}
|
||||
ListNode::add_to_list(malloced_list_tail, data);
|
||||
}
|
||||
|
||||
|
@ -118,10 +110,6 @@ namespace SC_AM_Internal {
|
|||
Malloced *data = reinterpret_cast<Malloced*>(real_malloc(sizeof(Malloced)));
|
||||
data->address = address;
|
||||
data->size = n * size;
|
||||
data->id = data->count++;
|
||||
if (is_env_status == ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
||||
std::clog << " id: " << data->id << std::endl;
|
||||
}
|
||||
ListNode::add_to_list(malloced_list_tail, data);
|
||||
}
|
||||
|
||||
|
@ -129,23 +117,19 @@ namespace SC_AM_Internal {
|
|||
return address;
|
||||
}
|
||||
|
||||
bool Stats::do_free(void *ptr) {
|
||||
bool result = false;
|
||||
void Stats::do_free(void *ptr) {
|
||||
if(int ret = pthread_mutex_lock(&pthread_mutex); ret == EINVAL) {
|
||||
std::clog << "ERROR: pthread mutex not properly initialized!\n";
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ptr) {
|
||||
if(!ListNode::remove_from_list(malloced_list_head, ptr)) {
|
||||
std::clog << "WARNING: Attempted free of unknown memory location!\n";
|
||||
} else {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pthread_mutex);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Stats::print_status() const {
|
||||
|
@ -158,9 +142,7 @@ namespace SC_AM_Internal {
|
|||
node = node->next;
|
||||
|
||||
if (node->data) {
|
||||
std::clog << " " << node->data->address
|
||||
<< ": size " << node->data->size
|
||||
<< " id " << node->data->id << '\n';
|
||||
std::clog << " " << node->data->address << ": size " << node->data->size << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ namespace SC_AM_Internal {
|
|||
|
||||
void* address;
|
||||
std::size_t size;
|
||||
unsigned long long id;
|
||||
static unsigned long long count;
|
||||
};
|
||||
|
||||
struct ListNode {
|
||||
|
@ -58,8 +56,7 @@ namespace SC_AM_Internal {
|
|||
|
||||
void *do_malloc(std::size_t size);
|
||||
void *do_calloc(std::size_t n, std::size_t size);
|
||||
/// true on success.
|
||||
bool do_free(void *ptr);
|
||||
void do_free(void *ptr);
|
||||
|
||||
void print_status() const;
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
||||
std::clog << "attempting to malloc size: " << size;
|
||||
std::clog << "attempting to malloc size: " << size << "...\n";
|
||||
}
|
||||
|
||||
return SC_AM_Internal::stats->do_malloc(size);
|
||||
|
@ -35,7 +35,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
||||
std::clog << "attempting to calloc size: " << size;
|
||||
std::clog << "attempting to calloc size: " << size << "...\n";
|
||||
}
|
||||
|
||||
return SC_AM_Internal::stats->do_calloc(n, size);
|
||||
|
@ -51,12 +51,10 @@ extern "C" {
|
|||
}
|
||||
|
||||
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
||||
std::clog << "attempting to free";
|
||||
std::clog << "attempting to free...\n";
|
||||
}
|
||||
|
||||
if (!SC_AM_Internal::stats->do_free(ptr)) {
|
||||
std::clog << std::endl;
|
||||
}
|
||||
return SC_AM_Internal::stats->do_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue