Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,21 @@
static void process_events(fsw_cevent const *const events, const unsigned int event_num, void *data) {

SEXP callback = (SEXP) data;
watcher_cb *wcb = NULL;

if (callback != R_NilValue) {

watcher_cb *wcb = calloc(1, sizeof(watcher_cb));
if (!wcb) return;
wcb = malloc(sizeof(watcher_cb));
if (wcb == NULL) goto fail;

wcb->event_num = event_num;
wcb->paths = calloc(event_num, sizeof(char *));
if (!wcb->paths) { watcher_unwind(wcb); return; }
wcb->callback = callback;
wcb->paths = calloc(event_num, sizeof(char *));
if (wcb->paths == NULL) goto fail;
for (unsigned int i = 0; i < event_num; i++) {
size_t slen = strlen(events[i].path) + 1;
wcb->paths[i] = malloc(sizeof(char) * slen);
if (!wcb->paths[i]) { watcher_unwind(wcb); return; }
if (wcb->paths[i] == NULL) goto fail;
memcpy(wcb->paths[i], events[i].path, slen);
}
eln2(exec_later, wcb, 0, 0);
Expand All @@ -79,6 +80,11 @@

}

return;

fail:
watcher_unwind(wcb);

Check warning on line 86 in src/watcher.c

View check run for this annotation

Codecov / codecov/patch

src/watcher.c#L85-L86

Added lines #L85 - L86 were not covered by tests

}

static void* watcher_thread(void *args) {
Expand Down
Loading