From 880a21830cc030edc11b7d1c195e8a7b61679e15 Mon Sep 17 00:00:00 2001 From: Keith Rarick Date: Wed, 14 Nov 2007 13:10:08 -0800 Subject: [PATCH] Fix a memory leak (#976). Normally conn_close() frees c->in_job, but enqueue_incoming_job() nulled out c->in_job before checking for the trailing "\r\n". This means that if the put command doesn't have a trailing "\r\n" after the job body, we would leak the job. --- beanstalkd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beanstalkd.c b/beanstalkd.c index 3a8dd28..36e5cdf 100644 --- a/beanstalkd.c +++ b/beanstalkd.c @@ -202,12 +202,12 @@ enqueue_incoming_job(conn c) int r; job j = c->in_job; - c->in_job = NULL; /* the connection no longer owns this job */ - c->in_job_read = 0; - /* check if the trailer is present and correct */ if (memcmp(j->body + j->body_size - 2, "\r\n", 2)) return conn_close(c); + c->in_job = NULL; /* the connection no longer owns this job */ + c->in_job_read = 0; + /* we have a complete job, so let's stick it in the pqueue */ r = enqueue_job(j, j->delay); put_ct++; /* stats */ -- 2.11.4.GIT