Memory leaks plugged

This commit is contained in:
Enno Rehling 2002-01-21 01:42:11 +00:00
parent f375f28a93
commit 359e711d4d
5 changed files with 11 additions and 16 deletions

View File

@ -460,7 +460,9 @@ stripfaction (faction * f)
#ifdef OLD_MESSAGES #ifdef OLD_MESSAGES
free_messages(f->msgs); free_messages(f->msgs);
#else #else
/* TODO */ /* TODO: inhalt auch löschen */
if (f->msgs) free(f->msgs);
if (f->battles) free(f->battles);
#endif #endif
/* TODO: free msgs */ /* TODO: free msgs */
freestrlist(f->mistakes); freestrlist(f->mistakes);

View File

@ -148,6 +148,7 @@ parse_plaintext(struct xml_stack *stack, const char *str)
if (strcmp(tagparent->name, "string")==0) { if (strcmp(tagparent->name, "string")==0) {
locale_setstring(state->lang, mkname(state->nspc, state->mtname), str); locale_setstring(state->lang, mkname(state->nspc, state->mtname), str);
} else { } else {
if (state->nrtext!=NULL) free(state->nrtext);
state->nrtext = strdup(str); state->nrtext = strdup(str);
} }
} }

View File

@ -331,11 +331,10 @@ parse(opstack ** stack, const char* inn, const void * userdata)
return NULL; return NULL;
} }
char * const char *
translate(const char* format, const void * userdata, const char* vars, const void* args[]) translate(const char* format, const void * userdata, const char* vars, const void* args[])
{ {
int i = 0; int i = 0;
char * retval;
const char *ic = vars; const char *ic = vars;
char symbol[32]; char symbol[32];
char *oc = symbol; 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; if (parse(&stack, format, userdata)==NULL) return NULL;
retval = strdup(opop(&stack, const char*)); return opop(&stack, const char*);
return retval;
} }
char * const char *
translate_va(const char* format, const void * userdata, const char* vars, ...) translate_va(const char* format, const void * userdata, const char* vars, ...)
{ {
char * retval;
va_list marker; va_list marker;
const char *ic = vars; const char *ic = vars;
char symbol[32]; char symbol[32];
@ -389,9 +385,7 @@ translate_va(const char* format, const void * userdata, const char* vars, ...)
va_end(marker); /* Reset variable arguments. */ va_end(marker); /* Reset variable arguments. */
if (parse(&stack, format, userdata)==NULL) return NULL; if (parse(&stack, format, userdata)==NULL) return NULL;
retval = strdup(opop(&stack, const char*)); return opop(&stack, const char*);
return retval;
} }
static void static void

View File

@ -18,8 +18,8 @@ extern void opstack_push(struct opstack ** stack, void * data);
extern void translation_init(void); extern void translation_init(void);
extern void translation_done(void); extern void translation_done(void);
extern char * translate_va(const char* format, const void * userdata, const char* vars, ...); extern const 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(const char* format, const void * userdata, const char* vars, const void* args[]);
/* eval_x functions */ /* eval_x functions */
typedef void (*evalfun)(struct opstack ** stack, const void *); typedef void (*evalfun)(struct opstack ** stack, const void *);

View File

@ -29,16 +29,14 @@ void
test_translation(void) test_translation(void)
{ {
int x; int x;
char * c; const char * c;
c = translate_va("\"$name is a godlike $role.\"", "name role", "enno", "coder"); c = translate_va("\"$name is a godlike $role.\"", "name role", "enno", "coder");
if (c) puts(c); if (c) puts(c);
free(c);
for (x=0;x!=4;++x) { for (x=0;x!=4;++x) {
c = translate_va(sample, "i", x); c = translate_va(sample, "i", x);
if (c) puts(c); if (c) puts(c);
free(c);
} }
} }