<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Copyright (c) 2017, <NAME> <<EMAIL>> */

#include <limits.h>
#include <sys/inotify.h>
#include <unistd.h>

#include <deai/builtins/event.h>
#include <deai/deai.h>
#include <deai/helper.h>

#include "uthash.h"
#include "utils.h"

struct di_file_watch_entry {
	const char *fname;
	int wd;
	UT_hash_handle hh, hh2;
};

struct di_file_watch {
	struct di_object;
	int fd;

	struct di_file_watch_entry *byname, *bywd;
};

static int di_file_ioev(struct di_weak_object *weak) {
	auto fw = (struct di_file_watch *)di_upgrade_weak_ref(weak);
	DI_CHECK(fw != NULL, "got ioev events but the listener has died");

	char evbuf[sizeof(struct inotify_event) + NAME_MAX + 1];
	struct inotify_event *ev = (void *)evbuf;<commit_msg>plugins: file: fix leak in di_file_ioev<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Copyright (c) 2017, <NAME> <<EMAIL>> */

#include <limits.h>
#include <sys/inotify.h>
#include <unistd.h>

#include <deai/builtins/event.h>
#include <deai/deai.h>
#include <deai/helper.h>

#include "uthash.h"
#include "utils.h"

struct di_file_watch_entry {
	const char *fname;
	int wd;
	UT_hash_handle hh, hh2;
};

struct di_file_watch {
	struct di_object;
	int fd;

	struct di_file_watch_entry *byname, *bywd;
};

define_object_cleanup(di_file_watch);
static int di_file_ioev(struct di_weak_object *weak) {
	with_object_cleanup(di_file_watch) fw = (void *)di_upgrade_weak_ref(weak);
	DI_CHECK(fw != NULL, "got ioev events but the listener has died");

	char evbuf[sizeof(struct inotify_event) + NAME_MAX + 1];
	struct inotify_event *ev = (void *)evbuf;
{'fraction_non_alphanumeric': 0.1284544524053224, 'fraction_numerical': 0.01023541453428864, 'mean_word_length': 4.683139534883721, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '309219', 'n_tokens_mistral': 772, 'n_tokens_neox': 746, 'n_words': 216}