#undef free
#undef vasprintf
+#define FENCE_MAGIC 0xdeadbeef
+
static FILE *mmlog;
static struct ast_region {
int lineno;
int which;
size_t len;
+ unsigned int fence;
unsigned char data[0];
} *regions[SOME_PRIME];
{
struct ast_region *reg;
void *ptr = NULL;
+ unsigned int *fence;
int hash;
- reg = malloc(size + sizeof(struct ast_region));
+ reg = malloc(size + sizeof(struct ast_region) + sizeof(unsigned int));
ast_mutex_lock(®lock);
if (reg) {
ast_copy_string(reg->file, file, sizeof(reg->file));
hash = HASH(ptr);
reg->next = regions[hash];
regions[hash] = reg;
+ reg->fence = FENCE_MAGIC;
+ fence = (ptr + reg->len);
+ *fence = FENCE_MAGIC;
}
ast_mutex_unlock(®lock);
if (!reg) {
{
int hash = HASH(ptr);
struct ast_region *reg, *prev = NULL;
+ unsigned int *fence;
+
ast_mutex_lock(®lock);
reg = regions[hash];
while (reg) {
}
ast_mutex_unlock(®lock);
if (reg) {
+ fence = (unsigned int *)(reg->data + reg->len);
+ if (reg->fence != FENCE_MAGIC) {
+ fprintf(stderr, "WARNING: Low fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
+ if (mmlog) {
+ fprintf(mmlog, "%ld - WARNING: Low fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg->file, reg->lineno);
+ fflush(mmlog);
+ }
+ }
+ if (*fence != FENCE_MAGIC) {
+ fprintf(stderr, "WARNING: High fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
+ if (mmlog) {
+ fprintf(mmlog, "%ld - WARNING: High fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg->file, reg->lineno);
+ fflush(mmlog);
+ }
+ }
free(reg);
} else {
fprintf(stderr, "WARNING: Freeing unused memory at %p, in %s of %s, line %d\n", ptr, func, file, lineno);
struct ast_region *reg;
unsigned int len = 0;
int count = 0;
+ unsigned int *fence;
if (argc > 3)
fn = argv[3];
for (x = 0; x < SOME_PRIME; x++) {
reg = regions[x];
while (reg) {
+ if (!fn || !strcasecmp(fn, reg->file) || !strcasecmp(fn, "anomolies")) {
+ fence = (unsigned int *)(reg->data + reg->len);
+ if (reg->fence != FENCE_MAGIC) {
+ fprintf(stderr, "WARNING: Low fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
+ if (mmlog) {
+ fprintf(mmlog, "%ld - WARNING: Low fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg-> file, reg->lineno);
+ fflush(mmlog);
+ }
+ }
+ if (*fence != FENCE_MAGIC) {
+ fprintf(stderr, "WARNING: High fence violation at %p, in %s of %s, line %d\n", reg->data, reg->func, reg->file, reg->lineno);
+ if (mmlog) {
+ fprintf(mmlog, "%ld - WARNING: High fence violation at %p, in %s of %s, line %d\n", time(NULL), reg->data, reg->func, reg->file, reg->lineno);
+ fflush(mmlog);
+ }
+ }
+ }
if (!fn || !strcasecmp(fn, reg->file)) {
ast_cli(fd, "%10d bytes allocated in %20s at line %5d of %s\n", (int) reg->len, reg->func, reg->lineno, reg->file);
len += reg->len;