X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2Ftimeq.c;h=ec9ea3e4017803440e5c5c63637e9b8aaa7ffbab;hp=7689b316f0fb35d2614c47d1b9ac212d31baa981;hb=HEAD;hpb=70b7d70a96523b78cd470c6fe2ab78beb345d607 diff --git a/src/timeq.c b/src/timeq.c index 7689b31..ec9ea3e 100644 --- a/src/timeq.c +++ b/src/timeq.c @@ -1,4 +1,4 @@ -/* timeq.c - NeonServ v5.5 +/* timeq.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,8 @@ #include "timeq.h" #include "IOHandler.h" +#include "tools.h" +#include "log.h" static struct timeq_entry *timeq_events; #ifdef HAVE_THREADS @@ -28,6 +30,10 @@ static IOHANDLER_CALLBACK(timeq_callback) { struct timeq_entry *entry = event->iofd->data; switch(event->type) { case IOEVENT_TIMEOUT: + if(entry->name) { + free(entry->name); + entry->name = NULL; + } entry->callback(entry->data); entry->iofd = NULL; timeq_del(entry); @@ -46,13 +52,15 @@ struct timeq_entry* timeq_uadd(int useconds, int module_id, timeq_callback_t *ca struct timeq_entry *entry = malloc(sizeof(*entry)); if (!entry) { - perror("malloc() failed"); + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); return NULL; } + #ifdef HAVE_THREADS if(!pthread_mutex_initialized) { THREAD_MUTEX_INIT(synchronized); pthread_mutex_initialized = 1; } + #endif gettimeofday(&timeout, NULL); SYNCHRONIZE(synchronized); timeout.tv_usec += (useconds % 1000); @@ -83,7 +91,9 @@ struct timeq_entry* timeq_uadd_name(char *name, int useconds, int module_id, tim } int timeq_del(struct timeq_entry* entry) { + #ifdef HAVE_THREADS if(!pthread_mutex_initialized) return 0; + #endif SYNCHRONIZE(synchronized); if(entry->next) entry->next->prev = entry->prev;