Permalink
Browse files

- fix some memory leaks

- removed SIGKILL handler (SIGKILL cannot be caught)
- exit when aped compiled without event handler
  • Loading branch information...
1 parent 42d6a12 commit 6e62786e63e4f8566055542dcf971ec9144f24e3 @harmer harmer committed with paraboul May 24, 2010
Showing with 86 additions and 6 deletions.
  1. +18 −0 src/config.c
  2. +4 −3 src/config.h
  3. +27 −3 src/entry.c
  4. +7 −0 src/events.c
  5. +2 −0 src/events.h
  6. +12 −0 src/ticks.c
  7. +1 −0 src/ticks.h
  8. +14 −0 src/transports.c
  9. +1 −0 src/transports.h
View
@@ -152,3 +152,21 @@ apeconfig *ape_config_load(const char *filename)
return conf;
}
+void ape_config_free(apeconfig *conf)
+{
+ apeconfig *tmp_s;
+ apeconfig_def *tmp_d;
+
+ while (conf != NULL) {
+ while (conf->def != NULL) {
+ tmp_d = conf->def->next;
+ free(conf->def->val);
+ free(conf->def);
+ conf->def = tmp_d;
+ }
+ tmp_s = conf->next;
+ free(conf);
+ conf = tmp_s;
+ }
+}
+
View
@@ -26,14 +26,14 @@
#define APE_CONFIG_FILE "ape.conf"
-struct _apeconfig_def {
+typedef struct _apeconfig_def {
char *val;
struct _apeconfig_def *next;
char key[33];
-};
+} apeconfig_def;
typedef struct apeconfig {
- struct _apeconfig_def *def;
+ apeconfig_def *def;
struct apeconfig *next;
char section[33];
} apeconfig;
@@ -42,6 +42,7 @@ typedef struct apeconfig {
apeconfig *ape_config_load(const char *filename);
char *ape_config_get_key(apeconfig *conf, const char *key);
apeconfig *ape_config_get_section(apeconfig *conf, const char *section);
+void ape_config_free(apeconfig *conf);
#define CONFIG_VAL(section, key, srv) \
(ape_config_get_key(ape_config_get_section(srv, #section), #key) == NULL ? "" : ape_config_get_key(ape_config_get_section(srv, #section), #key))
View
@@ -134,7 +134,6 @@ int main(int argc, char **argv)
signal(SIGINT, &signal_handler);
signal(SIGTERM, &signal_handler);
- signal(SIGKILL, &signal_handler);
if (VTICKS_RATE < 1) {
printf("[ERR] TICKS_RATE cant be less than 1\n");
@@ -158,6 +157,8 @@ int main(int argc, char **argv)
ape_log_init(g_ape);
+ fdev.handler = EVENT_UNKNOWN;
+
#ifdef USE_EPOLL_HANDLER
fdev.handler = EVENT_EPOLL;
#endif
@@ -174,7 +175,10 @@ int main(int argc, char **argv)
g_ape->timers.timers = NULL;
g_ape->timers.ntimers = 0;
g_ape->events = &fdev;
- events_init(g_ape, &g_ape->basemem);
+ if (events_init(g_ape, &g_ape->basemem) == -1) {
+ printf("Fatal error: APE compiled without an event handler... exiting\n");
+ return 0;
+ };
serverfd = servers_init(g_ape);
@@ -303,14 +307,34 @@ int main(int argc, char **argv)
unlink(pidfile);
}
+ free(confs_path);
+
+ timers_free(g_ape);
+
+ events_free(g_ape);
+
+ transport_free(g_ape);
+
hashtbl_free(g_ape->hLogin);
hashtbl_free(g_ape->hSessid);
hashtbl_free(g_ape->hLusers);
+ hashtbl_free(g_ape->hPubid);
hashtbl_free(g_ape->hCallback);
+ free(g_ape->bufout);
+
+ ape_config_free(srv);
+
+ int i;
+ for (i = 0; i < g_ape->basemem; i++) {
+ if (g_ape->co[i] != NULL) {
+ free(g_ape->co[i]);
+ }
+ }
+ free(g_ape->co);
+
free(g_ape->plugins);
- //free(srv);
free(g_ape);
return 0;
View
@@ -39,6 +39,13 @@ int events_init(acetables *g_ape, int *basemem)
return -1;
}
+void events_free(acetables *g_ape)
+{
+ if (g_ape->events->handler != EVENT_UNKNOWN) {
+ free(g_ape->events->events);
+ }
+}
+
int events_add(struct _fdevent *ev, int fd, int bitadd)
{
if (ev->add(ev, fd, bitadd) == -1) {
View
@@ -40,6 +40,7 @@
/* Events handler */
typedef enum {
+ EVENT_UNKNOWN,
EVENT_EPOLL, /* Linux */
EVENT_KQUEUE, /* BSD */
EVENT_DEVPOLL, /* Solaris */
@@ -72,6 +73,7 @@ struct _fdevent {
};
int events_init(acetables *g_ape, int *basemem);
+void events_free(acetables *g_ape);
int events_add(struct _fdevent *ev, int fd, int bitadd);
int events_poll(struct _fdevent *ev, int timeout_ms);
int events_get_current_fd(struct _fdevent *ev, int i);
View
@@ -155,3 +155,15 @@ int get_first_timer_ms(acetables *g_ape)
return -1;
}
+/* Delete all timers and deallocate memory */
+void timers_free(acetables *g_ape)
+{
+ struct _ticks_callback *timers = g_ape->timers.timers;
+ struct _ticks_callback *prev;
+
+ while (timers != NULL) {
+ prev = timers;
+ timers = timers->next;
+ free(prev);
+ }
+}
View
@@ -46,6 +46,7 @@ struct _ticks_callback *add_periodical(unsigned int msec, int times, void *callb
void del_timer_identifier(unsigned int identifier, acetables *g_ape);
struct _ticks_callback *get_timer_identifier(unsigned int identifier, acetables *g_ape);
int get_first_timer_ms(acetables *g_ape);
+void timers_free(acetables *g_ape);
#define add_ticked(x, y) add_periodical(VTICKS_RATE, 0, x, y, g_ape)
View
@@ -126,3 +126,17 @@ void transport_start(acetables *g_ape)
g_ape->transports.websocket.properties.padding.right.len = 1;
}
+
+void transport_free(acetables *g_ape)
+{
+ free(g_ape->transports.websocket.properties.padding.right.val);
+ free(g_ape->transports.websocket.properties.padding.left.val);
+ free(g_ape->transports.sse.properties.padding.right.val);
+ free(g_ape->transports.sse.properties.padding.left.val);
+ free(g_ape->transports.xhrstreaming.properties.padding.right.val);
+
+ if (g_ape->transports.jsonp.properties.padding.left.val != NULL) {
+ free(g_ape->transports.jsonp.properties.padding.left.val);
+ free(g_ape->transports.jsonp.properties.padding.right.val);
+ }
+}
View
@@ -47,6 +47,7 @@ typedef enum {
struct _transport_open_same_host_p transport_open_same_host(subuser *sub, ape_socket *client, transport_t transport);
void transport_data_completly_sent(subuser *sub, transport_t transport);
void transport_start(acetables *g_ape);
+void transport_free(acetables *g_ape);
struct _transport_properties *transport_get_properties(transport_t transport, acetables *g_ape);
#endif

0 comments on commit 6e62786

Please sign in to comment.