forked from cory/tildefriends
Fixed some memory leaks. Memory leak-related paranoia. Minor cleanups.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3659 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
35e0d8b68a
commit
e85168ac53
@ -199,6 +199,7 @@ void _socket_reportError(socket_t* socket, const char* error) {
|
|||||||
}
|
}
|
||||||
tf_task_run_jobs(socket->_task);
|
tf_task_run_jobs(socket->_task);
|
||||||
JS_FreeValue(tf_task_get_context(socket->_task), exception);
|
JS_FreeValue(tf_task_get_context(socket->_task), exception);
|
||||||
|
JS_FreeValue(tf_task_get_context(socket->_task), result);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Socket::reportError: %s\n", error);
|
fprintf(stderr, "Socket::reportError: %s\n", error);
|
||||||
}
|
}
|
||||||
@ -551,6 +552,7 @@ void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffe
|
|||||||
printf("Socket error on read.\n");
|
printf("Socket error on read.\n");
|
||||||
js_std_dump_error(tf_task_get_context(socket->_task));
|
js_std_dump_error(tf_task_get_context(socket->_task));
|
||||||
}
|
}
|
||||||
|
JS_FreeValue(tf_task_get_context(socket->_task), result);
|
||||||
tf_task_run_jobs(socket->_task);
|
tf_task_run_jobs(socket->_task);
|
||||||
}
|
}
|
||||||
_socket_close_internal(socket);
|
_socket_close_internal(socket);
|
||||||
@ -593,6 +595,7 @@ void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffe
|
|||||||
printf("Socket error on read plain.\n");
|
printf("Socket error on read plain.\n");
|
||||||
js_std_dump_error(tf_task_get_context(socket->_task));
|
js_std_dump_error(tf_task_get_context(socket->_task));
|
||||||
}
|
}
|
||||||
|
JS_FreeValue(tf_task_get_context(socket->_task), result);
|
||||||
tf_task_run_jobs(socket->_task);
|
tf_task_run_jobs(socket->_task);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -631,8 +634,9 @@ void _socket_notifyDataRead(socket_t* socket, const char* data, size_t length) {
|
|||||||
printf("Socket error on data read.\n");
|
printf("Socket error on data read.\n");
|
||||||
js_std_dump_error(tf_task_get_context(socket->_task));
|
js_std_dump_error(tf_task_get_context(socket->_task));
|
||||||
}
|
}
|
||||||
tf_task_run_jobs(socket->_task);
|
|
||||||
JS_FreeValue(tf_task_get_context(socket->_task), typedArray);
|
JS_FreeValue(tf_task_get_context(socket->_task), typedArray);
|
||||||
|
JS_FreeValue(tf_task_get_context(socket->_task), result);
|
||||||
|
tf_task_run_jobs(socket->_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
src/ssb.c
11
src/ssb.c
@ -473,13 +473,6 @@ bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* ou
|
|||||||
return verified;
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tf_ssb_send_createHistoryStream(tf_ssb_t* ssb, const char* id)
|
|
||||||
{
|
|
||||||
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) {
|
|
||||||
tf_ssb_rpc_send_createHistoryStream(connection, id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_send_close(tf_ssb_t* ssb)
|
void tf_ssb_send_close(tf_ssb_t* ssb)
|
||||||
{
|
{
|
||||||
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) {
|
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) {
|
||||||
@ -971,10 +964,8 @@ void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message)
|
|||||||
JSContext* context = ssb->context;
|
JSContext* context = ssb->context;
|
||||||
JSValue root = JS_NewObject(context);
|
JSValue root = JS_NewObject(context);
|
||||||
|
|
||||||
JSValue previousstr = JS_NULL;
|
|
||||||
if (have_previous) {
|
if (have_previous) {
|
||||||
previousstr = JS_NewString(context, previous_id);
|
JS_SetPropertyStr(context, root, "previous", JS_NewString(context, previous_id));
|
||||||
JS_SetPropertyStr(context, root, "previous", previousstr);
|
|
||||||
} else {
|
} else {
|
||||||
JS_SetPropertyStr(context, root, "previous", JS_NULL);
|
JS_SetPropertyStr(context, root, "previous", JS_NULL);
|
||||||
}
|
}
|
||||||
|
@ -310,6 +310,7 @@ static bool _tf_ssb_sqlite_bind_json(JSContext* context, sqlite3* db, sqlite3_st
|
|||||||
printf("expected string: %s\n", str);
|
printf("expected string: %s\n", str);
|
||||||
JS_FreeCString(context, str);
|
JS_FreeCString(context, str);
|
||||||
}
|
}
|
||||||
|
JS_FreeValue(context, value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("expected array\n");
|
printf("expected array\n");
|
||||||
|
@ -75,8 +75,6 @@ void tf_ssb_connect_str(tf_ssb_t* ssb, const char* address);
|
|||||||
void tf_ssb_server_open(tf_ssb_t* ssb, int port);
|
void tf_ssb_server_open(tf_ssb_t* ssb, int port);
|
||||||
void tf_ssb_server_close(tf_ssb_t* ssb);
|
void tf_ssb_server_close(tf_ssb_t* ssb);
|
||||||
|
|
||||||
void tf_ssb_send_createHistoryStream(tf_ssb_t* ssb, const char* id);
|
|
||||||
|
|
||||||
void tf_ssb_send_close(tf_ssb_t* ssb);
|
void tf_ssb_send_close(tf_ssb_t* ssb);
|
||||||
|
|
||||||
bool tf_ssb_id_str_to_bin(uint8_t* bin, const char* str);
|
bool tf_ssb_id_str_to_bin(uint8_t* bin, const char* str);
|
||||||
|
@ -59,6 +59,7 @@ static JSValue _tf_ssb_blobGet(JSContext* context, JSValueConst this_val, int ar
|
|||||||
result = JS_NewArrayBufferCopy(context, blob, size);
|
result = JS_NewArrayBufferCopy(context, blob, size);
|
||||||
free(blob);
|
free(blob);
|
||||||
}
|
}
|
||||||
|
JS_FreeCString(context, id);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -98,6 +99,7 @@ static JSValue _tf_ssb_messageContentGet(JSContext* context, JSValueConst this_v
|
|||||||
result = JS_NewArrayBufferCopy(context, blob, size);
|
result = JS_NewArrayBufferCopy(context, blob, size);
|
||||||
free(blob);
|
free(blob);
|
||||||
}
|
}
|
||||||
|
JS_FreeCString(context, id);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -120,17 +122,6 @@ static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, in
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue _tf_ssb_createHistoryStream(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
|
||||||
{
|
|
||||||
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
|
||||||
if (ssb) {
|
|
||||||
const char* id = JS_ToCString(context, argv[0]);
|
|
||||||
tf_ssb_send_createHistoryStream(ssb, id);
|
|
||||||
JS_FreeCString(context, id);
|
|
||||||
}
|
|
||||||
return JS_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _check_call(JSContext* context, JSValue result)
|
static void _check_call(JSContext* context, JSValue result)
|
||||||
{
|
{
|
||||||
if (JS_IsError(context, result))
|
if (JS_IsError(context, result))
|
||||||
@ -385,7 +376,6 @@ void _tf_ssb_on_rpc(tf_ssb_connection_t* connection, uint8_t flags, int32_t requ
|
|||||||
JSContext* context = tf_ssb_get_context(ssb);
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
|
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
|
||||||
JSValue object = JS_NewObject(context);
|
JSValue object = JS_NewObject(context);
|
||||||
printf("sending object = %d\n", JS_IsObject(tf_ssb_connection_get_object(connection)));
|
|
||||||
JSValue connection_object = JS_DupValue(context, tf_ssb_connection_get_object(connection));
|
JSValue connection_object = JS_DupValue(context, tf_ssb_connection_get_object(connection));
|
||||||
JS_SetPropertyStr(context, object, "connection", connection_object);
|
JS_SetPropertyStr(context, object, "connection", connection_object);
|
||||||
JS_SetPropertyStr(context, object, "flags", JS_NewUint32(context, flags));
|
JS_SetPropertyStr(context, object, "flags", JS_NewUint32(context, flags));
|
||||||
@ -462,7 +452,6 @@ static void _tf_ssb_on_blob_want_added(tf_ssb_t* ssb, const char* id, void* user
|
|||||||
static void _tf_ssb_cleanup_value(tf_ssb_t* ssb, void* user_data)
|
static void _tf_ssb_cleanup_value(tf_ssb_t* ssb, void* user_data)
|
||||||
{
|
{
|
||||||
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
|
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
|
||||||
printf("CLEANUP %p\n", user_data);
|
|
||||||
JS_FreeValue(tf_ssb_get_context(ssb), callback);
|
JS_FreeValue(tf_ssb_get_context(ssb), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,7 +462,6 @@ static JSValue _tf_ssb_register_blob_want_added(JSContext* context, JSValueConst
|
|||||||
{
|
{
|
||||||
return JS_ThrowTypeError(context, "Expected argument 1 to be a function.");
|
return JS_ThrowTypeError(context, "Expected argument 1 to be a function.");
|
||||||
}
|
}
|
||||||
printf("registering %p\n", JS_VALUE_GET_PTR(argv[0]));
|
|
||||||
tf_ssb_register_blob_want_added(ssb, _tf_ssb_on_blob_want_added, _tf_ssb_cleanup_value, JS_VALUE_GET_PTR(JS_DupValue(context, argv[0])));
|
tf_ssb_register_blob_want_added(ssb, _tf_ssb_on_blob_want_added, _tf_ssb_cleanup_value, JS_VALUE_GET_PTR(JS_DupValue(context, argv[0])));
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
@ -647,7 +635,6 @@ void tf_ssb_init(JSContext* context, tf_ssb_t* ssb)
|
|||||||
JS_SetPropertyStr(context, object, "blobStore", JS_NewCFunction(context, _tf_ssb_blobStore, "blobStore", 2));
|
JS_SetPropertyStr(context, object, "blobStore", JS_NewCFunction(context, _tf_ssb_blobStore, "blobStore", 2));
|
||||||
JS_SetPropertyStr(context, object, "messageContentGet", JS_NewCFunction(context, _tf_ssb_messageContentGet, "messageContentGet", 1));
|
JS_SetPropertyStr(context, object, "messageContentGet", JS_NewCFunction(context, _tf_ssb_messageContentGet, "messageContentGet", 1));
|
||||||
JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0));
|
JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0));
|
||||||
JS_SetPropertyStr(context, object, "createHistoryStream", JS_NewCFunction(context, _tf_ssb_createHistoryStream, "createHistoryStream", 1));
|
|
||||||
JS_SetPropertyStr(context, object, "sqlStream", JS_NewCFunction(context, _tf_ssb_sqlStream, "sqlStream", 3));
|
JS_SetPropertyStr(context, object, "sqlStream", JS_NewCFunction(context, _tf_ssb_sqlStream, "sqlStream", 3));
|
||||||
JS_SetPropertyStr(context, object, "post", JS_NewCFunction(context, _tf_ssb_post, "post", 1));
|
JS_SetPropertyStr(context, object, "post", JS_NewCFunction(context, _tf_ssb_post, "post", 1));
|
||||||
JS_SetPropertyStr(context, object, "appendMessage", JS_NewCFunction(context, _tf_ssb_appendMessage, "appendMessage", 1));
|
JS_SetPropertyStr(context, object, "appendMessage", JS_NewCFunction(context, _tf_ssb_appendMessage, "appendMessage", 1));
|
||||||
|
@ -9,6 +9,6 @@ typedef struct _tf_ssb_rpc_t tf_ssb_rpc_t;
|
|||||||
tf_ssb_rpc_t* tf_ssb_rpc_create(tf_ssb_t* ssb);
|
tf_ssb_rpc_t* tf_ssb_rpc_create(tf_ssb_t* ssb);
|
||||||
void tf_ssb_rpc_destroy(tf_ssb_rpc_t* rpc);
|
void tf_ssb_rpc_destroy(tf_ssb_rpc_t* rpc);
|
||||||
|
|
||||||
void tf_ssb_rpc_send_blobs_get(tf_ssb_connection_t* connection, const char* blob_id, size_t size);
|
/*void tf_ssb_rpc_send_blobs_get(tf_ssb_connection_t* connection, const char* blob_id, size_t size);
|
||||||
void tf_ssb_rpc_send_blobs_createWants(tf_ssb_connection_t* connection);
|
void tf_ssb_rpc_send_blobs_createWants(tf_ssb_connection_t* connection);
|
||||||
void tf_ssb_rpc_send_createHistoryStream(tf_ssb_connection_t* connection, const char* id);
|
void tf_ssb_rpc_send_createHistoryStream(tf_ssb_connection_t* connection, const char* id);*/
|
||||||
|
@ -341,6 +341,7 @@ static void _task_timeoutCallback(uv_timer_t* handle) {
|
|||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
tf_task_report_error(timeout->_task, result);
|
tf_task_report_error(timeout->_task, result);
|
||||||
|
JS_FreeValue(timeout->_task->_context, result);
|
||||||
tf_task_run_jobs(timeout->_task);
|
tf_task_run_jobs(timeout->_task);
|
||||||
tf_trace_end(timeout->_task->_trace);
|
tf_trace_end(timeout->_task->_trace);
|
||||||
free(timeout);
|
free(timeout);
|
||||||
@ -520,8 +521,10 @@ static void _forward_promise(tf_task_t* from, tf_taskstub_t* to, promiseid_t pro
|
|||||||
|
|
||||||
JSValue error = JS_Call(from->_context, promise_then, result, 1, &then_handler);
|
JSValue error = JS_Call(from->_context, promise_then, result, 1, &then_handler);
|
||||||
tf_task_report_error(from, error);
|
tf_task_report_error(from, error);
|
||||||
|
JS_FreeValue(from->_context, error);
|
||||||
error = JS_Call(from->_context, promise_catch, result, 1, &catch_handler);
|
error = JS_Call(from->_context, promise_catch, result, 1, &catch_handler);
|
||||||
tf_task_report_error(from, error);
|
tf_task_report_error(from, error);
|
||||||
|
JS_FreeValue(from->_context, error);
|
||||||
|
|
||||||
tf_task_run_jobs(from);
|
tf_task_run_jobs(from);
|
||||||
}
|
}
|
||||||
@ -1045,6 +1048,7 @@ void tf_task_resolve_promise(tf_task_t* task, promiseid_t promise, JSValue value
|
|||||||
tf_task_report_error(task, result);
|
tf_task_report_error(task, result);
|
||||||
JS_FreeValue(task->_context, it->values[1]);
|
JS_FreeValue(task->_context, it->values[1]);
|
||||||
JS_FreeValue(task->_context, it->values[2]);
|
JS_FreeValue(task->_context, it->values[2]);
|
||||||
|
JS_FreeValue(task->_context, result);
|
||||||
_tf_task_free_promise(task, promise);
|
_tf_task_free_promise(task, promise);
|
||||||
tf_task_run_jobs(task);
|
tf_task_run_jobs(task);
|
||||||
} else {
|
} else {
|
||||||
@ -1060,6 +1064,7 @@ void tf_task_reject_promise(tf_task_t* task, promiseid_t promise, JSValue value)
|
|||||||
tf_task_report_error(task, result);
|
tf_task_report_error(task, result);
|
||||||
JS_FreeValue(task->_context, it->values[1]);
|
JS_FreeValue(task->_context, it->values[1]);
|
||||||
JS_FreeValue(task->_context, it->values[2]);
|
JS_FreeValue(task->_context, it->values[2]);
|
||||||
|
JS_FreeValue(task->_context, result);
|
||||||
_tf_task_free_promise(task, promise);
|
_tf_task_free_promise(task, promise);
|
||||||
tf_task_run_jobs(task);
|
tf_task_run_jobs(task);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user