From 359e711d4d0533258913ef294a9ee848f50e5c87 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 21 Jan 2002 01:42:11 +0000 Subject: [PATCH] Memory leaks plugged --- src/common/kernel/eressea.c | 4 +++- src/common/kernel/message.c | 1 + src/common/util/translation.c | 14 ++++---------- src/common/util/translation.h | 4 ++-- src/tools/translator.c | 4 +--- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 0bbb7e540..b291f7085 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -460,7 +460,9 @@ stripfaction (faction * f) #ifdef OLD_MESSAGES free_messages(f->msgs); #else - /* TODO */ + /* TODO: inhalt auch löschen */ + if (f->msgs) free(f->msgs); + if (f->battles) free(f->battles); #endif /* TODO: free msgs */ freestrlist(f->mistakes); diff --git a/src/common/kernel/message.c b/src/common/kernel/message.c index 55c5bef3f..99ba47040 100644 --- a/src/common/kernel/message.c +++ b/src/common/kernel/message.c @@ -148,6 +148,7 @@ parse_plaintext(struct xml_stack *stack, const char *str) if (strcmp(tagparent->name, "string")==0) { locale_setstring(state->lang, mkname(state->nspc, state->mtname), str); } else { + if (state->nrtext!=NULL) free(state->nrtext); state->nrtext = strdup(str); } } diff --git a/src/common/util/translation.c b/src/common/util/translation.c index e15a24217..6ade52591 100644 --- a/src/common/util/translation.c +++ b/src/common/util/translation.c @@ -331,11 +331,10 @@ parse(opstack ** stack, const char* inn, const void * userdata) return NULL; } -char * +const char * translate(const char* format, const void * userdata, const char* vars, const void* args[]) { int i = 0; - char * retval; const char *ic = vars; char symbol[32]; char *oc = symbol; @@ -357,15 +356,12 @@ translate(const char* format, const void * userdata, const char* vars, const voi } if (parse(&stack, format, userdata)==NULL) return NULL; - retval = strdup(opop(&stack, const char*)); - - return retval; + return opop(&stack, const char*); } -char * +const char * translate_va(const char* format, const void * userdata, const char* vars, ...) { - char * retval; va_list marker; const char *ic = vars; char symbol[32]; @@ -389,9 +385,7 @@ translate_va(const char* format, const void * userdata, const char* vars, ...) va_end(marker); /* Reset variable arguments. */ if (parse(&stack, format, userdata)==NULL) return NULL; - retval = strdup(opop(&stack, const char*)); - - return retval; + return opop(&stack, const char*); } static void diff --git a/src/common/util/translation.h b/src/common/util/translation.h index d76d74e73..b7e38784f 100644 --- a/src/common/util/translation.h +++ b/src/common/util/translation.h @@ -18,8 +18,8 @@ extern void opstack_push(struct opstack ** stack, void * data); extern void translation_init(void); extern void translation_done(void); -extern char * translate_va(const char* format, const void * userdata, const char* vars, ...); -extern char * translate(const char* format, const void * userdata, const char* vars, const void* args[]); +extern const char * translate_va(const char* format, const void * userdata, const char* vars, ...); +extern const char * translate(const char* format, const void * userdata, const char* vars, const void* args[]); /* eval_x functions */ typedef void (*evalfun)(struct opstack ** stack, const void *); diff --git a/src/tools/translator.c b/src/tools/translator.c index d27c97e84..12e222d20 100644 --- a/src/tools/translator.c +++ b/src/tools/translator.c @@ -29,16 +29,14 @@ void test_translation(void) { int x; - char * c; + const char * c; c = translate_va("\"$name is a godlike $role.\"", "name role", "enno", "coder"); if (c) puts(c); - free(c); for (x=0;x!=4;++x) { c = translate_va(sample, "i", x); if (c) puts(c); - free(c); } }