Commit 59ef0fbb04d990e3da749f15fa552d14310442f7

Authored by Georg Hopp
1 parent ac224684

some leak fixes ... but now I have a strange segfault in during cleanup, but onl…

…y if the caller of eventHandlerClassCleanup is build with optimizations.
@@ -50,6 +50,10 @@ void TR_eventHandlerSetDispatcher(TR_EventHandler, TR_EventDispatcher); @@ -50,6 +50,10 @@ void TR_eventHandlerSetDispatcher(TR_EventHandler, TR_EventDispatcher);
50 void TR_eventHandlerIssueEvent(TR_EventHandler, TR_EventSubject, int, void *); 50 void TR_eventHandlerIssueEvent(TR_EventHandler, TR_EventSubject, int, void *);
51 int TR_eventHandlerHandleEvent(TR_EventHandler, TR_Event); 51 int TR_eventHandlerHandleEvent(TR_EventHandler, TR_Event);
52 52
  53 +#define TR_eventHandlerClassCleanup(cname) \
  54 + (TR__eventHandlerClassCleanup(TR_CLASS_BY_NAME(cname)))
  55 +void TR__eventHandlerClassCleanup(TR_class_ptr);
  56 +
53 #define TR_EVENT_HANDLER_SET_METHOD(cls, subject, id, method) \ 57 #define TR_EVENT_HANDLER_SET_METHOD(cls, subject, id, method) \
54 do { \ 58 do { \
55 intptr_t key = TR_eventSubjectId(subject, id); \ 59 intptr_t key = TR_eventSubjectId(subject, id); \
@@ -15,6 +15,7 @@ TREVENT = event.c \ @@ -15,6 +15,7 @@ TREVENT = event.c \
15 event_handler_handle_event.c \ 15 event_handler_handle_event.c \
16 event_handler_issue_event.c \ 16 event_handler_issue_event.c \
17 event_handler_set_dispatcher.c \ 17 event_handler_set_dispatcher.c \
  18 + event_handler_class_cleanup.c \
18 event_subject.c \ 19 event_subject.c \
19 event_subject_emit.c \ 20 event_subject_emit.c \
20 event_subject_id.c 21 event_subject_id.c
@@ -46,8 +46,17 @@ eventDispatcherCtor(void * _this, va_list * params) { @@ -46,8 +46,17 @@ eventDispatcherCtor(void * _this, va_list * params) {
46 46
47 static 47 static
48 void 48 void
  49 +releaseHandlerQueues(const void * node, const void * data)
  50 +{
  51 + TR_delete(*(void**)((TR_HashValue)node)->value);
  52 +}
  53 +
  54 +static
  55 +void
49 eventDispatcherDtor(void * _this) { 56 eventDispatcherDtor(void * _this) {
50 - TR_EventDispatcher this = _this; 57 + TR_EventDispatcher this = _this;
  58 +
  59 + TR_hashEach(this->handler, NULL, releaseHandlerQueues);
51 60
52 TR_hashCleanup(this->handler); 61 TR_hashCleanup(this->handler);
53 TR_delete(this->handler); 62 TR_delete(this->handler);
@@ -39,7 +39,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this) @@ -39,7 +39,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
39 time_t now = time(NULL); 39 time_t now = time(NULL);
40 TR_Event current = NULL; 40 TR_Event current = NULL;
41 41
42 - if (this->nextbeat && this->nextbeat < now) { 42 + if (this->nextbeat && this->nextbeat <= now) {
43 this->nextbeat += this->heartbeat; 43 this->nextbeat += this->heartbeat;
44 TR_eventDispatcherEnqueueEvent( 44 TR_eventDispatcherEnqueueEvent(
45 this, 45 this,
@@ -86,6 +86,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this) @@ -86,6 +86,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
86 queue_node = queue_node->next; 86 queue_node = queue_node->next;
87 } 87 }
88 } 88 }
  89 +
  90 + TR_delete(current);
89 } 91 }
90 } 92 }
91 } 93 }
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2014 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include "trbase.h"
  24 +#include "trhash.h"
  25 +
  26 +#include "tr/event_handler.h"
  27 +
  28 +void
  29 +TR__eventHandlerClassCleanup(TR_class_ptr class)
  30 +{
  31 + while (class) {
  32 + struct c_TR_EventHandler_vars * vars;
  33 + vars = (struct c_TR_EventHandler_vars *)class->vars;
  34 + TR_delete(vars->event_methods);
  35 + class = class->parent;
  36 + }
  37 +}
  38 +
  39 +// vim: set ts=4 sw=4:
Please register or login to post a comment