add some comment, and free data where error

This commit is contained in:
云风
2013-06-18 15:33:06 +08:00
parent 9c1e59b690
commit 48528d97ad
3 changed files with 20 additions and 3 deletions

View File

@@ -207,6 +207,10 @@ _cb(struct skynet_context * ctx, void * ud, int type, int session, uint32_t sour
mread_push(m, id, (void *)(data+4), sz - 4, (void *)data);
return 1;
} else {
// data is malloc by
// service-src/service-client.c : 18
// uint8_t *tmp = malloc(sz + 4 + 2);
free((void *)data);
skynet_error(ctx, "Invalid client id %d from %x",(int)uid,source);
return 0;
}

View File

@@ -214,6 +214,9 @@ mread_push(struct mread_pool *self, int id, void * buffer, int size, void * ptr)
break;
}
if (sz == size) {
// ptr is malloc by
// service-src/service-client.c : 18
// uint8_t *tmp = malloc(sz + 4 + 2);
free(ptr);
return;
}
@@ -369,9 +372,7 @@ mread_close(struct mread_pool *self) {
free_buffer(&s->client);
free(s);
if (self->listen_fd >= 0) {
close(self->listen_fd);
}
mread_close_listen(self);
#ifdef HAVE_EPOLL
close(self->epoll_fd);
#elif HAVE_KQUEUE
@@ -381,6 +382,17 @@ mread_close(struct mread_pool *self) {
free(self);
}
void
mread_close_listen(struct mread_pool *self) {
if (self == NULL)
return;
if (self->listen_fd >= 0) {
close(self->listen_fd);
self->listen_fd = 0;
}
}
static int
_read_queue(struct mread_pool * self, int timeout) {
self->queue_head = 0;

View File

@@ -15,5 +15,6 @@ void mread_yield(struct mread_pool *m);
int mread_closed(struct mread_pool *m);
void mread_close_client(struct mread_pool *m, int id);
int mread_socket(struct mread_pool *m , int index);
void mread_close_listen(struct mread_pool *self);
#endif