diff --git a/unix/uxagentc.c b/unix/uxagentc.c index 51f9a1eb..2c748343 100644 --- a/unix/uxagentc.c +++ b/unix/uxagentc.c @@ -95,6 +95,8 @@ void agent_cancel_query(agent_pending_query *conn) uxsel_del(conn->fd); close(conn->fd); del234(agent_pending_queries, conn); + if (conn->retbuf && conn->retbuf != conn->sizebuf) + sfree(conn->retbuf); sfree(conn); } @@ -114,11 +116,12 @@ static void agent_select_result(int fd, int event) return; /* more data to come */ /* - * We have now completed the agent query. Do the callback, and - * clean up. (Of course we don't free retbuf, since ownership - * of that passes to the callback.) + * We have now completed the agent query. Do the callback. */ conn->callback(conn->callback_ctx, conn->retbuf, conn->retlen); + /* Null out conn->retbuf, since ownership of that buffer has + * passed to the callback. */ + conn->retbuf = NULL; agent_cancel_query(conn); }