Fix one possible but not actually relevant leak around files, and remove an unused value from promises.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3857 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-03-07 21:57:52 +00:00
parent 41cabad264
commit 7e9460f47c
2 changed files with 9 additions and 8 deletions

View File

@ -125,6 +125,7 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar
if (result < 0)
{
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result)));
free(req);
}
JS_FreeCString(context, file_name);
return promise_value;

View File

@ -60,7 +60,7 @@ typedef struct _promise_t promise_t;
typedef struct _promise_t
{
promiseid_t id;
JSValue values[3];
JSValue values[2];
} promise_t;
typedef struct _tf_task_t
@ -1181,9 +1181,9 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
promise_t promise =
{
.id = promiseId,
.values = { JS_NULL, JS_NULL, JS_NULL },
.values = { JS_NULL, JS_NULL },
};
promise.values[0] = JS_NewPromiseCapability(task->_context, &promise.values[1]);
JSValue result = JS_NewPromiseCapability(task->_context, promise.values);
int index = _insert_index((void*)(intptr_t)promiseId, task->_promises, task->_promise_count, sizeof(promise_t), _promise_compare);
task->_promises = realloc(task->_promises, sizeof(promise_t) * (task->_promise_count + 1));
if (task->_promise_count - index)
@ -1193,7 +1193,7 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
task->_promises[index] = promise;
task->_promise_count++;
*out_promise = promiseId;
return promise.values[0];
return result;
}
void tf_task_resolve_promise(tf_task_t* task, promiseid_t promise, JSValue value)
@ -1201,10 +1201,10 @@ void tf_task_resolve_promise(tf_task_t* task, promiseid_t promise, JSValue value
promise_t* it = _tf_task_find_promise(task, promise);
if (it)
{
JSValue result = JS_Call(task->_context, it->values[1], JS_UNDEFINED, 1, &value);
JSValue result = JS_Call(task->_context, it->values[0], JS_UNDEFINED, 1, &value);
tf_util_report_error(task->_context, result);
JS_FreeValue(task->_context, it->values[0]);
JS_FreeValue(task->_context, it->values[1]);
JS_FreeValue(task->_context, it->values[2]);
JS_FreeValue(task->_context, result);
_tf_task_free_promise(task, promise);
}
@ -1227,14 +1227,14 @@ void tf_task_reject_promise(tf_task_t* task, promiseid_t promise, JSValue value)
arg = JS_GetException(task->_context);
free_arg = true;
}
JSValue result = JS_Call(task->_context, it->values[2], JS_UNDEFINED, 1, &arg);
JSValue result = JS_Call(task->_context, it->values[1], JS_UNDEFINED, 1, &arg);
if (free_arg)
{
JS_FreeValue(task->_context, arg);
}
tf_util_report_error(task->_context, result);
JS_FreeValue(task->_context, it->values[0]);
JS_FreeValue(task->_context, it->values[1]);
JS_FreeValue(task->_context, it->values[2]);
JS_FreeValue(task->_context, result);
_tf_task_free_promise(task, promise);
}