Permalink
Browse files

Fix subscribe leak.

  • Loading branch information...
nicolasff committed Jan 26, 2011
1 parent 3e63a07 commit 9378544d1942930d8fc70a705bcea7be58125c6f
Showing with 21 additions and 12 deletions.
  1. +3 −3 client.c
  2. +1 −7 cmd.c
  3. +1 −1 formats/common.c
  4. +1 −1 http.c
  5. +12 −0 server.c
  6. +3 −0 server.h
View
@@ -77,7 +77,7 @@ http_client_read(int fd, short event, void *ctx) {
http_client_free(c);
break;
- default:
+ default: /* CLIENT_EXECUTING */
break;
}
}
@@ -129,8 +129,8 @@ http_client_free(struct http_client *c) {
close(c->fd);
if(c->sub) {
- /* clean up redis object */
- redisAsyncFree(c->sub->s->ac);
+ /* clean up Redis connection */
+ server_free(c->sub->s);
/* clean up command object */
if(c->sub->cmd) {
View
8 cmd.c
@@ -240,13 +240,7 @@ cmd_select_format(struct http_client *client, struct cmd *cmd,
int
cmd_is_subscribe(struct cmd *cmd) {
- /*
- if(cmd->started_responding) {
- return 1;
- }
- */
-
- if(cmd->count >= 1 &&
+ if(cmd->count >= 1 &&
(strncasecmp(cmd->argv[0], "SUBSCRIBE", cmd->argv_len[0]) == 0 ||
strncasecmp(cmd->argv[0], "PSUBSCRIBE", cmd->argv_len[0]) == 0)) {
return 1;
View
@@ -22,7 +22,7 @@ char *etag_new(const char *p, size_t sz) {
for(i = 0; i < 16; ++i) {
sprintf(etag + 1 + 2*i, "%.2x", (unsigned char)buf[i]);
}
-
+
etag[0] = '"';
etag[33] = '"';
View
2 http.c
@@ -88,7 +88,7 @@ http_response_write(struct http_response *r, int fd) {
p += r->headers[i].sz;
sz += r->headers[i].sz;
}
-
+
/* end of headers */
s = realloc(s, sz + 2);
memcpy(s + sz, "\r\n", 2);
View
@@ -84,6 +84,18 @@ server_new(const char *filename) {
return s;
}
+void
+server_free(struct server *s) {
+
+ /* cleanup Redis async object, _before_ the 2 struct event. */
+ redisAsyncFree(s->ac);
+
+ event_del(&s->ev);
+ event_del(&s->ev_reconnect);
+
+ free(s);
+}
+
static void
connectCallback(const redisAsyncContext *c) {
((void)c);
View
@@ -26,6 +26,9 @@ webdis_connect(struct server *s);
struct server *
server_new(const char *filename);
+void
+server_free(struct server *s);
+
struct server *
server_copy(const struct server *s);

0 comments on commit 9378544

Please sign in to comment.