Permalink
Browse files

- Fix a memory leak when using server-side JS socket in "line mode" (…

…flushlf)
  • Loading branch information...
1 parent c8777e7 commit 6d9f56ec266ee103fab4daea7212f2ef1d485d5f @paraboul paraboul committed Nov 12, 2010
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/sock.c
View
17 src/sock.c 100755 → 100644
@@ -445,20 +445,23 @@ unsigned int sockroutine(acetables *g_ape)
}
if (g_ape->co[active_fd]->callbacks.on_read_lf != NULL) {
- int eol, len = g_ape->co[active_fd]->buffer_in.length;
+ unsigned int eol, *len = &g_ape->co[active_fd]->buffer_in.length;
char *pBuf = g_ape->co[active_fd]->buffer_in.data;
- while ((eol = sneof(pBuf, len, 4096)) != -1) {
+ while ((eol = sneof(pBuf, *len, 4096)) != -1) {
pBuf[eol-1] = '\0';
g_ape->co[active_fd]->callbacks.on_read_lf(g_ape->co[active_fd], pBuf, g_ape);
pBuf = &pBuf[eol];
- len -= eol;
+ *len -= eol;
}
- if (len > 4096 || !len) {
+ if (*len > 4096 || !*len) {
g_ape->co[active_fd]->buffer_in.length = 0;
- } else if (len) {
- memmove(g_ape->co[active_fd]->buffer_in.data, &g_ape->co[active_fd]->buffer_in.data[g_ape->co[active_fd]->buffer_in.length - len], len);
- g_ape->co[active_fd]->buffer_in.length = len;
+ } else if (*len && pBuf != g_ape->co[active_fd]->buffer_in.data) {
+
+ memmove(g_ape->co[active_fd]->buffer_in.data,
+ pBuf,
+ *len);
+
}
}

0 comments on commit 6d9f56e

Please sign in to comment.