Browse Source

some leak fixes ... but now I have a strange segfault in during cleanup, but only if the caller of eventHandlerClassCleanup is build with optimizations.

1.0.0
Georg Hopp 12 years ago
parent
commit
59ef0fbb04
  1. 4
      include/tr/event_handler.h
  2. 1
      src/Makefile.am
  3. 9
      src/event_dispatcher.c
  4. 4
      src/event_dispatcher_start.c
  5. 39
      src/event_handler_class_cleanup.c

4
include/tr/event_handler.h

@ -50,6 +50,10 @@ void TR_eventHandlerSetDispatcher(TR_EventHandler, TR_EventDispatcher);
void TR_eventHandlerIssueEvent(TR_EventHandler, TR_EventSubject, int, void *); void TR_eventHandlerIssueEvent(TR_EventHandler, TR_EventSubject, int, void *);
int TR_eventHandlerHandleEvent(TR_EventHandler, TR_Event); int TR_eventHandlerHandleEvent(TR_EventHandler, TR_Event);
#define TR_eventHandlerClassCleanup(cname) \
(TR__eventHandlerClassCleanup(TR_CLASS_BY_NAME(cname)))
void TR__eventHandlerClassCleanup(TR_class_ptr);
#define TR_EVENT_HANDLER_SET_METHOD(cls, subject, id, method) \ #define TR_EVENT_HANDLER_SET_METHOD(cls, subject, id, method) \
do { \ do { \
intptr_t key = TR_eventSubjectId(subject, id); \ intptr_t key = TR_eventSubjectId(subject, id); \

1
src/Makefile.am

@ -15,6 +15,7 @@ TREVENT = event.c \
event_handler_handle_event.c \ event_handler_handle_event.c \
event_handler_issue_event.c \ event_handler_issue_event.c \
event_handler_set_dispatcher.c \ event_handler_set_dispatcher.c \
event_handler_class_cleanup.c \
event_subject.c \ event_subject.c \
event_subject_emit.c \ event_subject_emit.c \
event_subject_id.c event_subject_id.c

9
src/event_dispatcher.c

@ -44,11 +44,20 @@ eventDispatcherCtor(void * _this, va_list * params) {
return 0; return 0;
} }
static
void
releaseHandlerQueues(const void * node, const void * data)
{
TR_delete(*(void**)((TR_HashValue)node)->value);
}
static static
void void
eventDispatcherDtor(void * _this) { eventDispatcherDtor(void * _this) {
TR_EventDispatcher this = _this; TR_EventDispatcher this = _this;
TR_hashEach(this->handler, NULL, releaseHandlerQueues);
TR_hashCleanup(this->handler); TR_hashCleanup(this->handler);
TR_delete(this->handler); TR_delete(this->handler);
TR_delete(this->events); TR_delete(this->events);

4
src/event_dispatcher_start.c

@ -39,7 +39,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
time_t now = time(NULL); time_t now = time(NULL);
TR_Event current = NULL; TR_Event current = NULL;
if (this->nextbeat && this->nextbeat < now) {
if (this->nextbeat && this->nextbeat <= now) {
this->nextbeat += this->heartbeat; this->nextbeat += this->heartbeat;
TR_eventDispatcherEnqueueEvent( TR_eventDispatcherEnqueueEvent(
this, this,
@ -86,6 +86,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
queue_node = queue_node->next; queue_node = queue_node->next;
} }
} }
TR_delete(current);
} }
} }
} }

39
src/event_handler_class_cleanup.c

@ -0,0 +1,39 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trbase.h"
#include "trhash.h"
#include "tr/event_handler.h"
void
TR__eventHandlerClassCleanup(TR_class_ptr class)
{
while (class) {
struct c_TR_EventHandler_vars * vars;
vars = (struct c_TR_EventHandler_vars *)class->vars;
TR_delete(vars->event_methods);
class = class->parent;
}
}
// vim: set ts=4 sw=4:
Loading…
Cancel
Save