did I find a useless memory leak?

7 views
Skip to first unread message

daniel

unread,
Dec 27, 2009, 1:00:16 AM12/27/09
to gearman
Project: gearmand
Version: 0.11
OS: CentOS / ami-3d3d6c78

Hi,

I was trying to figure out why some ruby code wasn't working properly
and I was reading though the source code of gearmand, when I noticed
this in

libgearman-server/server.c

/* Worker requests. */
case GEARMAN_COMMAND_CAN_DO:
if (gearman_server_worker_add(server_con, (char *)(packet->arg
[0]),
packet->arg_size[0], 0) == NULL)

Following the code to

libgearman-server/worker.c

gearman_server_worker_st *
gearman_server_worker_add(gearman_server_con_st *con, const char
*function_name,
size_t function_name_size, uint32_t timeout)
{
gearman_server_worker_st *worker;
gearman_server_function_st *function;

function= gearman_server_function_get(con->thread->server,
function_name, function_name_size);
if (function == NULL)
return NULL;

worker= gearman_server_worker_create(con, function, NULL);

## D. If the above gearman_server_function_get works, but the
## gearman_server_worker_create fails, the code returns NULL
immediately.
## But no one release the memory for the local variable function,
which was malloc'd in
## File: libgearman-server\function.c ~ line 41
## function->function_name= malloc(function_name_size + 1);

if (worker == NULL)
return NULL;


-daniel

Eric Day

unread,
Dec 27, 2009, 1:54:38 PM12/27/09
to gea...@googlegroups.com
This is on purpose. Function entires in the server are persistent. Once
they are created, they do not get cleaned up currently. At some point I
was going to add in code to clean up stale functions after some period
of time, but I didn't want to free everytime the queue size went to 0.

-Eric

Reply all
Reply to author
Forward
0 new messages