copy names of callbacks when registering them

This commit is contained in:
Enno Rehling 2014-07-03 05:15:38 -07:00
parent 162375842b
commit f505ae8eb7
1 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,5 @@
#include <config.h>
#include <platform.h>
#include "callback.h" #include "callback.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -5,7 +7,7 @@
static struct reg { static struct reg {
struct reg * next; struct reg * next;
CALLBACK cb; CALLBACK cb;
const char *name; char *name;
} *registry; } *registry;
CALLBACK create_callback(void (*cbv)(va_list va)) { CALLBACK create_callback(void (*cbv)(va_list va)) {
@ -15,6 +17,12 @@ CALLBACK create_callback(void (*cbv)(va_list va)) {
} }
void reset_callbacks(void) { void reset_callbacks(void) {
while(registry) {
struct reg *r = registry;
registry = r->next;
free(r->name);
free(r);
}
registry = 0; registry = 0;
} }
@ -22,7 +30,7 @@ CALLBACK register_callback(const char *name, void (*cbv)(va_list va))
{ {
struct reg * r = (struct reg *)malloc(sizeof(struct reg)); struct reg * r = (struct reg *)malloc(sizeof(struct reg));
r->next = registry; r->next = registry;
r->name = name; r->name = _strdup(name);
r->cb.cbv = cbv; r->cb.cbv = cbv;
registry = r; registry = r;
return r->cb; return r->cb;