Browse Source

Fix two memory leaks in RPC:

* on REHASH rpc-user block name was not freed
* temporary construct was not freed (if params was missing)
pull/48/head
Bram Matthys 6 months ago
parent
commit
14215e1837
No known key found for this signature in database
GPG Key ID: BF8116B163EAAE98
  1. 20
      src/modules/rpc/rpc.c

20
src/modules/rpc/rpc.c

@ -99,6 +99,7 @@ void free_config(void)
for (e = rpcusers; e; e = e_next)
{
e_next = e->next;
safe_free(e->name);
free_security_group(e->match);
Auth_FreeAuthConfig(e->auth);
safe_free(e);
@ -518,6 +519,7 @@ void rpc_call(Client *client, json_t *request)
const char *jsonrpc;
const char *method;
json_t *params;
char params_allocated = 0;
RPCHandler *handler;
jsonrpc = json_object_get_string(request, "jsonrpc");
@ -532,6 +534,14 @@ void rpc_call(Client *client, json_t *request)
rpc_error(client, request, JSON_RPC_ERROR_INVALID_REQUEST, "Missing 'method' to call");
return;
}
handler = RPCHandlerFind(method);
if (!handler)
{
rpc_error(client, request, JSON_RPC_ERROR_METHOD_NOT_FOUND, "Unsupported method");
return;
}
params = json_object_get(request, "params");
if (!params)
{
@ -539,13 +549,7 @@ void rpc_call(Client *client, json_t *request)
* to make life easier of the RPC handlers (no need to check NULL).
*/
params = json_object();
}
handler = RPCHandlerFind(method);
if (!handler)
{
rpc_error(client, request, JSON_RPC_ERROR_METHOD_NOT_FOUND, "Unsupported method");
return;
params_allocated = 1;
}
unreal_log(ULOG_INFO, "rpc", "RPC_CALL", client,
@ -553,6 +557,8 @@ void rpc_call(Client *client, json_t *request)
log_data_string("method", method));
handler->call(client, request, params);
if (params_allocated)
json_decref(params);
}
/** Called very early on accept() of the socket, before TLS is ready */

Loading…
Cancel
Save