Crashbug in der Auswertung, reference count bei magie-message nicht richtig (ADDMSG Makro)

This commit is contained in:
Enno Rehling 2004-04-18 12:24:33 +00:00
parent c1f37f78e3
commit a6e923896d
1 changed files with 38 additions and 24 deletions

View File

@ -15,6 +15,7 @@
#include "message.h" #include "message.h"
#include "goodies.h" #include "goodies.h"
#include "log.h"
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
@ -35,6 +36,11 @@ mt_new(const char * name, const char * args[])
int i, nparameters = 0; int i, nparameters = 0;
message_type * mtype = (message_type *)malloc(sizeof(message_type)); message_type * mtype = (message_type *)malloc(sizeof(message_type));
assert(name!=NULL);
if (name!=NULL) {
log_error(("Trying to create message_type with name=0x0\n"));
return NULL;
}
if (args!=NULL) for (nparameters=0;args[nparameters];++nparameters); if (args!=NULL) for (nparameters=0;args[nparameters];++nparameters);
mtype->name = strdup(name); mtype->name = strdup(name);
@ -85,6 +91,12 @@ msg_create(const struct message_type * type, void * args[])
{ {
int i; int i;
message * msg = (message *)malloc(sizeof(message)); message * msg = (message *)malloc(sizeof(message));
assert(type!=NULL);
if (type==NULL) {
log_error(("Trying to create message with type=0x0\n"));
return NULL;
}
msg->type = type; msg->type = type;
msg->parameters = calloc(sizeof(void*), type->nparameters); msg->parameters = calloc(sizeof(void*), type->nparameters);
msg->refcount=1; msg->refcount=1;
@ -160,6 +172,7 @@ msg_free(message *msg)
void void
msg_release(struct message * msg) msg_release(struct message * msg)
{ {
assert(msg->refcount>0);
if (--msg->refcount>0) return; if (--msg->refcount>0) return;
msg_free(msg); msg_free(msg);
} }
@ -167,6 +180,7 @@ msg_release(struct message * msg)
struct message * struct message *
msg_addref(struct message * msg) msg_addref(struct message * msg)
{ {
assert(msg->refcount>0);
++msg->refcount; ++msg->refcount;
return msg; return msg;
} }