Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak fixes (in progress) #59

Merged
merged 9 commits into from
Oct 20, 2016
10 changes: 5 additions & 5 deletions src/api/register.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "api/sb-api.h"

int api_register(string name, string desc,
string author, string license, array functions, struct connection *con,
uint32_t msgid, struct api_error *api_error)
string author, string license, array functions, uint64_t con_id,
uint32_t msgid, char *pluginkey, struct api_error *api_error)
{
struct message_object *func;
array params = ARRAY_INIT;
Expand All @@ -33,7 +33,7 @@ int api_register(string name, string desc,
return (-1);
}

if (db_plugin_add(con->cc.pluginkeystring, name, desc, author, license) == -1) {
if (db_plugin_add(pluginkey, name, desc, author, license) == -1) {
error_set(api_error, API_ERROR_TYPE_VALIDATION,
"Failed to register plugin in database.");
return (-1);
Expand All @@ -48,7 +48,7 @@ int api_register(string name, string desc,
continue;
}

if (db_function_add(con->cc.pluginkeystring, &func->data.params) == -1) {
if (db_function_add(pluginkey, &func->data.params) == -1) {
error_set(api_error, API_ERROR_TYPE_VALIDATION,
"Failed to register function in database.");
continue;
Expand All @@ -58,7 +58,7 @@ int api_register(string name, string desc,
if (api_error->isset)
return (-1);

if (connection_send_response(con, msgid, params, api_error) < 0) {
if (connection_send_response(con_id, msgid, params, api_error) < 0) {
return (-1);
};

Expand Down
4 changes: 2 additions & 2 deletions src/api/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "sb-common.h"

int api_result(char *targetpluginkey, uint64_t callid,
struct message_object args, struct connection *con, uint32_t msgid,
struct message_object args, uint64_t con_id, uint32_t msgid,
struct api_error *api_error)
{
struct message_object *data;
Expand Down Expand Up @@ -90,7 +90,7 @@ int api_result(char *targetpluginkey, uint64_t callid,
result_response_params.obj[0].type = OBJECT_TYPE_UINT;
result_response_params.obj[0].data.uinteger = callid;

if (connection_send_response(con, msgid, result_response_params, api_error) < 0) {
if (connection_send_response(con_id, msgid, result_response_params, api_error) < 0) {
return (-1);
};

Expand Down
4 changes: 2 additions & 2 deletions src/api/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "api/sb-api.h"

int api_run(char *targetpluginkey, string function_name, uint64_t callid,
struct message_object args, struct connection *con,
struct message_object args, uint64_t con_id,
uint32_t msgid, struct api_error *api_error)
{
struct message_object *data;
Expand Down Expand Up @@ -110,7 +110,7 @@ int api_run(char *targetpluginkey, string function_name, uint64_t callid,
run_response_params.obj[0].type = OBJECT_TYPE_UINT;
run_response_params.obj[0].data.uinteger = callid;

if (connection_send_response(con, msgid, run_response_params, api_error) < 0) {
if (connection_send_response(con_id, msgid, run_response_params, api_error) < 0) {
return (-1);
};

Expand Down
10 changes: 5 additions & 5 deletions src/api/sb-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* @return 0 in case of success otherwise 1
*/
int api_register(string name, string desc,
string author, string license, array functions, struct connection *con,
uint32_t msgid, struct api_error *api_error);
string author, string license, array functions, uint64_t con_id,
uint32_t msgid, char *pluginkey, struct api_error *api_error);

/**
* Run a plugin function
Expand All @@ -47,8 +47,8 @@
* @return 0 in case of success otherwise -1
*/
int api_run(char *targetpluginkey, string function_name, uint64_t callid,
struct message_object args, struct connection *con,
uint32_t msgid, struct api_error *api_error);
struct message_object args, uint64_t con_id, uint32_t msgid,
struct api_error *api_error);

/**
* Generates an API key using /dev/urandom. The length of the key
Expand All @@ -59,5 +59,5 @@ int api_run(char *targetpluginkey, string function_name, uint64_t callid,
int api_get_key(string key);

int api_result(char *targetpluginkey, uint64_t callid,
struct message_object args, struct connection *con, uint32_t msgid,
struct message_object args, uint64_t con_id, uint32_t msgid,
struct api_error *api_error);
16 changes: 13 additions & 3 deletions src/hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@
kh_clear(T##_##U##_map, map->table); \
}

MAP_IMPL(cstr_t, ptr_t, DEFAULT_INITIALIZER) /* maps pluginkey <> connection */
/* callid -> pluginkey
* connection id -> connection */
MAP_IMPL(uint64_t, ptr_t, DEFAULT_INITIALIZER)

/* pluginkey -> connection
* formatted address to listen to -> server */
MAP_IMPL(cstr_t, ptr_t, DEFAULT_INITIALIZER)

/* RPC function name -> dispatch info */
MAP_IMPL(string, dispatch_info, {.func = NULL, .async = false, .name = {.str = NULL, .length = 0}})
MAP_IMPL(uint64_t, string, {.str = NULL, .length = 0})
MAP_IMPL(uint64_t, ptr_t, DEFAULT_INITIALIZER) /* maps callid <> pluginkey */

/* pluginkey -> connection id */
MAP_IMPL(cstr_t, uint64_t, DEFAULT_INITIALIZER)

Loading