Added tracing to strdup for allocations, fixed some memleaks, this isn't pretty (trying to track down some weird memory leak issues)

This commit is contained in:
Dale Weiler 2013-04-14 23:51:16 +00:00
parent 18fad16a7d
commit ef528d6710
7 changed files with 34 additions and 22 deletions

View file

@ -10,7 +10,7 @@ CYGWIN = $(findstring CYGWIN, $(UNAME))
MINGW = $(findstring MINGW32, $(UNAME)) MINGW = $(findstring MINGW32, $(UNAME))
CC ?= clang CC ?= clang
CFLAGS += -Wall -Wextra -Werror -I. -fno-strict-aliasing -fsigned-char $(OPTIONAL) CFLAGS += -Wall -Wextra -Werror -I. -fno-strict-aliasing -fsigned-char -ffunction-sections -fdata-sections -Wl,-gc-sections $(OPTIONAL)
ifneq ($(shell git describe --always 2>/dev/null),) ifneq ($(shell git describe --always 2>/dev/null),)
CFLAGS += -DGMQCC_GITINFO="\"$(shell git describe --always)\"" CFLAGS += -DGMQCC_GITINFO="\"$(shell git describe --always)\""
endif endif

1
ast.c
View file

@ -584,6 +584,7 @@ void ast_member_delete(ast_member *self)
* purpose that is not garbage-collected. * purpose that is not garbage-collected.
*/ */
ast_expression_delete((ast_expression*)self); ast_expression_delete((ast_expression*)self);
mem_d(self->name);
mem_d(self); mem_d(self);
} }

24
ftepp.c
View file

@ -492,22 +492,28 @@ static bool ftepp_define(ftepp_t *ftepp)
break; break;
default: default:
ftepp_error(ftepp, "expected macro name"); ftepp_error(ftepp, "expected macro name");
goto cleanup_false; return false;
} }
(void)ftepp_next(ftepp); (void)ftepp_next(ftepp);
if (ftepp->token == '(') { if (ftepp->token == '(') {
macro->has_params = true; macro->has_params = true;
if (!ftepp_define_params(ftepp, macro)) if (!ftepp_define_params(ftepp, macro)) {
goto cleanup_false; ppmacro_delete(macro);
return false;
}
} }
if (!ftepp_skipspace(ftepp)) if (!ftepp_skipspace(ftepp)) {
goto cleanup_false; ppmacro_delete(macro);
return false;
}
if (!ftepp_define_body(ftepp, macro)) if (!ftepp_define_body(ftepp, macro)) {
goto cleanup_false; ppmacro_delete(macro);
return false;
}
if (ftepp->output_on) if (ftepp->output_on)
vec_push(ftepp->macros, macro); vec_push(ftepp->macros, macro);
@ -518,10 +524,6 @@ static bool ftepp_define(ftepp_t *ftepp)
for (; l < ftepp_ctx(ftepp).line; ++l) for (; l < ftepp_ctx(ftepp).line; ++l)
ftepp_out(ftepp, "\n", true); ftepp_out(ftepp, "\n", true);
return true; return true;
cleanup_false:
if (macro) ppmacro_delete(macro);
return false;
} }
/** /**

View file

@ -300,7 +300,7 @@ void util_meminfo ();
bool util_filexists (const char *); bool util_filexists (const char *);
bool util_strupper (const char *); bool util_strupper (const char *);
bool util_strdigit (const char *); bool util_strdigit (const char *);
char *util_strdup (const char *); char *_util_Estrdup (const char *, const char *, size_t);
void util_debug (const char *, const char *, ...); void util_debug (const char *, const char *, ...);
void util_endianswap (void *, size_t, unsigned int); void util_endianswap (void *, size_t, unsigned int);
@ -326,6 +326,8 @@ int util_asprintf (char **ret, const char *fmt, ...);
# define mem_r(x, n) util_memory_r((void*)(x), (n), __LINE__, __FILE__) # define mem_r(x, n) util_memory_r((void*)(x), (n), __LINE__, __FILE__)
#endif /*! NOTRACK */ #endif /*! NOTRACK */
#define util_strdup(X) _util_Estrdup((X), __FILE__, __LINE__)
/* /*
* A flexible vector implementation: all vector pointers contain some * A flexible vector implementation: all vector pointers contain some
* data about themselfs exactly - sizeof(vector_t) behind the pointer * data about themselfs exactly - sizeof(vector_t) behind the pointer

View file

@ -44,10 +44,6 @@ ht intrin_intrinsics() {
return intrinsics; return intrinsics;
} }
void intrin_intrinsics_destroy() {
util_htdel(intrin_intrinsics());
}
#define INTRIN_VAL(VALUE, NAME, FUNC, STYPE, VTYPE) \ #define INTRIN_VAL(VALUE, NAME, FUNC, STYPE, VTYPE) \
do { \ do { \
(VALUE) = ast_value_new ( \ (VALUE) = ast_value_new ( \
@ -376,6 +372,17 @@ static intrin_t intrinsics[] = {
{&intrin_isnan, "__builtin_isnan", "isnan"} {&intrin_isnan, "__builtin_isnan", "isnan"}
}; };
void intrin_intrinsics_destroy(parser_t *parser) {
/*size_t i;*/
(void)parser;
util_htdel(intrin_intrinsics());
#if 0
for (i = 0; i < sizeof(intrinsics)/sizeof(intrin_t); i++)
ast_value_delete( (ast_value*) intrinsics[i].intrin(parser));
#endif
}
ast_expression *intrin_func(parser_t *parser, const char *name) { ast_expression *intrin_func(parser_t *parser, const char *name) {
static bool init = false; static bool init = false;
size_t i = 0; size_t i = 0;

View file

@ -6093,7 +6093,7 @@ void parser_cleanup()
util_htdel(parser->aliases); util_htdel(parser->aliases);
intrin_intrinsics_destroy(); intrin_intrinsics_destroy(parser);
mem_d(parser); mem_d(parser);
} }

8
util.c
View file

@ -136,13 +136,13 @@ void util_meminfo() {
return; return;
for (info = mem_start; info; info = info->next) { for (info = mem_start; info; info = info->next) {
util_debug("MEM", "lost: % 8u (bytes) at %s:%u\n", con_out("lost: % 8u (bytes) at %s:%u\n",
info->byte, info->byte,
info->file, info->file,
info->line); info->line);
} }
util_debug("MEM", "Memory information:\n\ con_out("Memory information:\n\
Total allocations: %llu\n\ Total allocations: %llu\n\
Total deallocations: %llu\n\ Total deallocations: %llu\n\
Total allocated: %llu (bytes)\n\ Total allocated: %llu (bytes)\n\
@ -159,14 +159,14 @@ void util_meminfo() {
* Some string utility functions, because strdup uses malloc, and we want * Some string utility functions, because strdup uses malloc, and we want
* to track all memory (without replacing malloc). * to track all memory (without replacing malloc).
*/ */
char *util_strdup(const char *s) { char *_util_Estrdup(const char *s, const char *file, size_t line) {
size_t len = 0; size_t len = 0;
char *ptr = NULL; char *ptr = NULL;
if (!s) if (!s)
return NULL; return NULL;
if ((len = strlen(s)) && (ptr = (char*)mem_a(len+1))) { if ((len = strlen(s)) && (ptr = (char*)util_memory_a(len+1, line, file))) {
memcpy(ptr, s, len); memcpy(ptr, s, len);
ptr[len] = '\0'; ptr[len] = '\0';
} }