Updated more things to use xfree(&foo) instead of free(foo)
This commit is contained in:
parent
9d1f51c483
commit
f4a7b80b4f
13
compiler.c
13
compiler.c
@ -351,7 +351,7 @@ vm_op_t *bp_simplepattern(file_t *f, const char *str)
|
||||
// Parentheses
|
||||
case '(': case '{': {
|
||||
char closing = c == '(' ? ')' : '}';
|
||||
free(op);
|
||||
xfree(&op);
|
||||
op = bp_simplepattern(f, str);
|
||||
if (!op)
|
||||
file_err(f, str, str, "There should be a valid pattern after this parenthesis.");
|
||||
@ -428,8 +428,8 @@ vm_op_t *bp_simplepattern(file_t *f, const char *str)
|
||||
op->args.s = strndup(&c, 1);
|
||||
}
|
||||
if (matchchar(&str, ':')) { // Don't match definitions
|
||||
free((char*)op->args.s);
|
||||
free(op);
|
||||
xfree(&op->args.s);
|
||||
xfree(&op);
|
||||
return NULL;
|
||||
}
|
||||
op->op = VM_REF;
|
||||
@ -442,14 +442,14 @@ vm_op_t *bp_simplepattern(file_t *f, const char *str)
|
||||
const char *refname = str;
|
||||
str = after_name(str);
|
||||
if (matchchar(&str, ':')) { // Don't match definitions
|
||||
free(op);
|
||||
xfree(&op);
|
||||
return NULL;
|
||||
}
|
||||
op->op = VM_REF;
|
||||
op->args.s = strndup(refname, (size_t)(str - refname));
|
||||
break;
|
||||
} else {
|
||||
free(op);
|
||||
xfree(&op);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -535,8 +535,7 @@ vm_op_t *bp_stringpattern(file_t *f, const char *str)
|
||||
strop->end = str;
|
||||
|
||||
if (strop->len == 0) {
|
||||
free(strop);
|
||||
strop = NULL;
|
||||
xfree(&strop);
|
||||
} else {
|
||||
ret = chain_together(ret, strop);
|
||||
}
|
||||
|
@ -103,30 +103,29 @@ void intern_file(file_t *f)
|
||||
f->contents = buf;
|
||||
f->end = buf + size;
|
||||
f->mmapped = 0;
|
||||
free(f->lines);
|
||||
xfree(&f->lines);
|
||||
populate_lines(f);
|
||||
}
|
||||
|
||||
void destroy_file(file_t **f)
|
||||
{
|
||||
if ((*f)->filename) {
|
||||
free((char*)(*f)->filename);
|
||||
xfree(&((*f)->filename));
|
||||
(*f)->filename = NULL;
|
||||
}
|
||||
if ((*f)->lines) {
|
||||
free((*f)->lines);
|
||||
xfree(&((*f)->lines));
|
||||
(*f)->lines = NULL;
|
||||
}
|
||||
if ((*f)->contents) {
|
||||
if ((*f)->mmapped) {
|
||||
munmap((*f)->contents, (size_t)((*f)->end - (*f)->contents));
|
||||
} else {
|
||||
free((*f)->contents);
|
||||
xfree(&((*f)->contents));
|
||||
}
|
||||
(*f)->contents = NULL;
|
||||
}
|
||||
free(*f);
|
||||
*f = NULL;
|
||||
xfree(f);
|
||||
}
|
||||
|
||||
size_t get_line_number(file_t *f, const char *p)
|
||||
|
@ -119,8 +119,8 @@ void pop_backrefs(grammar_t *g, size_t count)
|
||||
backref_t *b = g->firstbackref;
|
||||
g->firstbackref = b->next;
|
||||
check(b, "Attempt to pop %ld more backrefs than there are", count);
|
||||
xfree((void**)&b->op);
|
||||
xfree((void**)&b);
|
||||
xfree(&b->op);
|
||||
xfree(&b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ static void _visualize_matches(match_node_t *firstmatch, int depth, const char *
|
||||
|
||||
for (match_node_t *c = children, *next = NULL; c; c = next) {
|
||||
next = c->next;
|
||||
free(c);
|
||||
xfree(&c);
|
||||
}
|
||||
}
|
||||
|
||||
|
8
utils.c
8
utils.c
@ -214,9 +214,13 @@ int memicmp(const void *v1, const void *v2, size_t n)
|
||||
/*
|
||||
* Free memory, but also set the pointer to NULL for safety
|
||||
*/
|
||||
void xfree(void **p)
|
||||
void xfree(void *p)
|
||||
{
|
||||
free(*p);
|
||||
if (*(void**)p == NULL) {
|
||||
fprintf(stderr, "Attempt to free(NULL)\n");
|
||||
_exit(1);
|
||||
}
|
||||
free(*(void**)p);
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
|
2
utils.h
2
utils.h
@ -34,7 +34,7 @@ void *memcheck(void *p);
|
||||
__attribute__((nonnull))
|
||||
int memicmp(const void *s1, const void *s2, size_t n);
|
||||
__attribute__((nonnull))
|
||||
void xfree(void **p);
|
||||
void xfree(void *p);
|
||||
|
||||
#endif
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
|
||||
|
Loading…
Reference in New Issue
Block a user