Skip to content

Commit 735d853

Browse files
committedFeb 28, 2024
fswatch: use the JS allocator
1 parent 59b17af commit 735d853

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎src/fswatch.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void uv__fsevent_close_cb(uv_handle_t *handle) {
4444
if (fw) {
4545
fw->closed = 1;
4646
if (fw->finalized)
47-
free(fw);
47+
js_free(fw->ctx, fw);
4848
}
4949
}
5050

@@ -59,7 +59,7 @@ static void tjs_fswatch_finalizer(JSRuntime *rt, JSValue val) {
5959
JS_FreeValueRT(rt, fw->callback);
6060
fw->finalized = 1;
6161
if (fw->closed)
62-
free(fw);
62+
js_free_rt(rt, fw);
6363
else
6464
maybe_close(fw);
6565
}
@@ -167,7 +167,7 @@ static JSValue tjs_fs_watch(JSContext *ctx, JSValueConst this_val, int argc, JSV
167167
return JS_EXCEPTION;
168168
}
169169

170-
TJSFsWatch *fw = calloc(1, sizeof(*fw));
170+
TJSFsWatch *fw = js_mallocz(ctx, sizeof(*fw));
171171
if (!fw) {
172172
JS_FreeCString(ctx, path);
173173
JS_FreeValue(ctx, obj);
@@ -178,15 +178,15 @@ static JSValue tjs_fs_watch(JSContext *ctx, JSValueConst this_val, int argc, JSV
178178
if (r != 0) {
179179
JS_FreeCString(ctx, path);
180180
JS_FreeValue(ctx, obj);
181-
free(fw);
181+
js_free(ctx, fw);
182182
return JS_ThrowInternalError(ctx, "couldn't initialize handle");
183183
}
184184

185185
r = uv_fs_event_start(&fw->handle, uv__fs_event_cb, path, UV_FS_EVENT_RECURSIVE);
186186
if (r != 0) {
187187
JS_FreeCString(ctx, path);
188188
JS_FreeValue(ctx, obj);
189-
free(fw);
189+
js_free(ctx, fw);
190190
return tjs_throw_errno(ctx, r);
191191
}
192192

0 commit comments

Comments
 (0)