]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Added tracing to strdup for allocations, fixed some memleaks, this isn't pretty ...
authorDale Weiler <killfieldengine@gmail.com>
Sun, 14 Apr 2013 23:51:16 +0000 (23:51 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 14 Apr 2013 23:51:16 +0000 (23:51 +0000)
Makefile
ast.c
ftepp.c
gmqcc.h
intrin.h
parser.c
util.c

index c72b237ffa3078951bce17351789c44070048e96..41ae2e6c112d171f183ab5d4673300f5129c6422 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ CYGWIN  = $(findstring CYGWIN,  $(UNAME))
 MINGW   = $(findstring MINGW32, $(UNAME))
 
 CC     ?= clang
 MINGW   = $(findstring MINGW32, $(UNAME))
 
 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),)
     CFLAGS += -DGMQCC_GITINFO="\"$(shell git describe --always)\""
 endif
 ifneq ($(shell git describe --always 2>/dev/null),)
     CFLAGS += -DGMQCC_GITINFO="\"$(shell git describe --always)\""
 endif
diff --git a/ast.c b/ast.c
index 919e0a636e9befadfc3b4400bb56d09853ef831c..b1b7ba826cc9b7a3d085c993fbcd3a1c24e0c58e 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -584,6 +584,7 @@ void ast_member_delete(ast_member *self)
      * purpose that is not garbage-collected.
     */
     ast_expression_delete((ast_expression*)self);
      * purpose that is not garbage-collected.
     */
     ast_expression_delete((ast_expression*)self);
+    mem_d(self->name);
     mem_d(self);
 }
 
     mem_d(self);
 }
 
diff --git a/ftepp.c b/ftepp.c
index 7337ba3571efec36117426617adadc856757991f..af3e699d59a716c8c47dca049bc3ca74d345b97b 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -492,22 +492,28 @@ static bool ftepp_define(ftepp_t *ftepp)
             break;
         default:
             ftepp_error(ftepp, "expected macro name");
             break;
         default:
             ftepp_error(ftepp, "expected macro name");
-            goto cleanup_false;
+            return false;
     }
 
     (void)ftepp_next(ftepp);
 
     if (ftepp->token == '(') {
         macro->has_params = true;
     }
 
     (void)ftepp_next(ftepp);
 
     if (ftepp->token == '(') {
         macro->has_params = true;
-        if (!ftepp_define_params(ftepp, macro))
-            goto cleanup_false;
+        if (!ftepp_define_params(ftepp, macro)) {
+            ppmacro_delete(macro);
+            return false;
+        }
     }
 
     }
 
-    if (!ftepp_skipspace(ftepp))
-        goto cleanup_false;
+    if (!ftepp_skipspace(ftepp)) {
+        ppmacro_delete(macro);
+        return false;
+    }
 
 
-    if (!ftepp_define_body(ftepp, macro))
-        goto cleanup_false;
+    if (!ftepp_define_body(ftepp, macro)) {
+        ppmacro_delete(macro);
+        return false;
+    }
 
     if (ftepp->output_on)
         vec_push(ftepp->macros, macro);
 
     if (ftepp->output_on)
         vec_push(ftepp->macros, macro);
@@ -518,10 +524,6 @@ static bool ftepp_define(ftepp_t *ftepp)
     for (; l < ftepp_ctx(ftepp).line; ++l)
         ftepp_out(ftepp, "\n", true);
     return true;
     for (; l < ftepp_ctx(ftepp).line; ++l)
         ftepp_out(ftepp, "\n", true);
     return true;
-
-cleanup_false:
-    if (macro) ppmacro_delete(macro);
-    return false;
 }
 
 /**
 }
 
 /**
diff --git a/gmqcc.h b/gmqcc.h
index fbddf15da657ef89321d047c4d7d14a7b1ef64de..223e0d7559e2ce4e9bb80fedcc482b0a48e88109 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -300,7 +300,7 @@ void  util_meminfo       ();
 bool  util_filexists     (const char *);
 bool  util_strupper      (const char *);
 bool  util_strdigit      (const char *);
 bool  util_filexists     (const char *);
 bool  util_strupper      (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_endianswap    (void *,  size_t, unsigned int);
 
 void  util_debug         (const char *, const char *, ...);
 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__)
 #endif /*! NOTRACK */
 
 #    define mem_r(x, n) util_memory_r((void*)(x), (n), __LINE__, __FILE__)
 #endif /*! NOTRACK */
 
+#define util_strdup(X)  _util_Estrdup((X), __FILE__, __LINE__)
+
 /*
  * A flexible vector implementation: all vector pointers contain some
  * data about themselfs exactly - sizeof(vector_t) behind the pointer
 /*
  * A flexible vector implementation: all vector pointers contain some
  * data about themselfs exactly - sizeof(vector_t) behind the pointer
index d66cc3c1f9ee191460231f442c4b5fb87d561653..69490dc7cd522ef00a314230f6911e217fa32bb5 100644 (file)
--- a/intrin.h
+++ b/intrin.h
@@ -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)                   \
     do {                                                              \
         (VALUE) = ast_value_new (                                     \
 #define INTRIN_VAL(VALUE, NAME, FUNC, STYPE, VTYPE)                   \
     do {                                                              \
         (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) {
     static bool  init = false;
     size_t       i    = 0;
 ast_expression *intrin_func(parser_t *parser, const char *name) {
     static bool  init = false;
     size_t       i    = 0;
index 3cae34cd40451224c4099a798b7a33a0ec3ac4a4..db714549af5b9415ddc4b245503dbc9f5c8ab7b1 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -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);
 }
diff --git a/util.c b/util.c
index 023eb5e8e52899878993eef0eaac5cbd210c7f69..2e2aec356822e15913c0bb37986e33499be4f963 100644 (file)
--- a/util.c
+++ b/util.c
@@ -136,13 +136,13 @@ void util_meminfo() {
         return;
 
     for (info = mem_start; info; info = info->next) {
         return;
 
     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->file,
             info->line);
     }
 
             info->byte,
             info->file,
             info->line);
     }
 
-    util_debug("MEM", "Memory information:\n\
+    con_out("Memory information:\n\
         Total allocations:   %llu\n\
         Total deallocations: %llu\n\
         Total allocated:     %llu (bytes)\n\
         Total allocations:   %llu\n\
         Total deallocations: %llu\n\
         Total allocated:     %llu (bytes)\n\
@@ -159,14 +159,14 @@ void util_meminfo() {
  * Some string utility functions, because strdup uses malloc, and we want
  * to track all memory (without replacing malloc).
  */
  * Some string utility functions, because strdup uses malloc, and we want
  * 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;
     char   *ptr = NULL;
 
     if (!s)
         return NULL;
 
     size_t  len = 0;
     char   *ptr = NULL;
 
     if (!s)
         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);
         ptr[len] = '\0';
     }
         memcpy(ptr, s, len);
         ptr[len] = '\0';
     }