From 19acd9a5b696cbb14bf9c2e77d71b9a19ef4a17b Mon Sep 17 00:00:00 2001 From: Sven Date: Sun, 5 Apr 2026 18:49:59 +0200 Subject: [PATCH] Remove `freed` variable from data structs This should be fine since the data pointer is being set to NULL after a free, which will now gets checked instead of the `freed` variable --- src/fdi_hook.c | 6 +----- src/fis_hook.c | 10 ++-------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/fdi_hook.c b/src/fdi_hook.c index b87e86b..b7cd9fd 100644 --- a/src/fdi_hook.c +++ b/src/fdi_hook.c @@ -14,7 +14,6 @@ struct fdi_file_data { char *data; size_t index; size_t length; - int freed; size_t inode; size_t device; }; @@ -62,7 +61,6 @@ jint JNICALL und_open0_hook(JNIEnv *env, jobject thiz, jlong path_address, file_data.data = data; file_data.length = fd_len; file_data.index = 0; - file_data.freed = 0; file_data.inode = st.st_ino; file_data.device = st.st_dev; hmput(fdi_files_map, fd, file_data); @@ -103,14 +101,13 @@ jint JNICALL fdi_read0_hook(JNIEnv *env, jobject thiz, jobject fdObject, return fdi_real_read0(env, thiz, fdObject, address, len); } - if (file_data->freed) { + if (file_data->data == NULL) { return -1; } if (file_data->length == 0) { free(file_data->data); file_data->data = NULL; - file_data->freed = 1; return -1; } @@ -120,7 +117,6 @@ jint JNICALL fdi_read0_hook(JNIEnv *env, jobject thiz, jobject fdObject, if (n == file_data->length - file_data->index) { free(file_data->data); file_data->data = NULL; - file_data->freed = 1; } else { file_data->index += n; } diff --git a/src/fis_hook.c b/src/fis_hook.c index 810ed3e..2b5c12a 100644 --- a/src/fis_hook.c +++ b/src/fis_hook.c @@ -18,7 +18,6 @@ struct fis_file_data { char *data; size_t index; size_t length; - int freed; }; struct file { @@ -39,7 +38,7 @@ jint JNICALL fis_readBytes_hook(JNIEnv *env, jobject thiz, jbyteArray buf, jint hash = (*env)->CallIntMethod(env, thiz, hash_code_method); struct file *file = hmgetp_null(fis_files_map, hash); - if (file == NULL || file->value.freed) { + if (file == NULL || file->value.data == NULL) { return -1; } @@ -63,7 +62,6 @@ jint JNICALL fis_readBytes_hook(JNIEnv *env, jobject thiz, jbyteArray buf, if (fd->index == fd->length) { free(fd->data); fd->data = NULL; - fd->freed = 1; } return len_to_read; @@ -120,7 +118,6 @@ void JNICALL fis_open0_hook(JNIEnv *env, jobject thiz, jstring jpath) { file_data.data = data; file_data.length = fd_len; file_data.index = 0; - file_data.freed = 0; hmput(fis_files_map, hash, file_data); (*env)->ReleaseStringUTFChars(env, jpath, path); } @@ -137,7 +134,7 @@ jint JNICALL fis_read0_hook(JNIEnv *env, jobject thiz) { jint hash = (*env)->CallIntMethod(env, thiz, hash_code_method); struct file *file = hmgetp_null(fis_files_map, hash); - if (file == NULL || file->value.freed) { + if (file == NULL || file->value.data == NULL) { return -1; } @@ -146,7 +143,6 @@ jint JNICALL fis_read0_hook(JNIEnv *env, jobject thiz) { if (fd->data[fd->index] == '\0') { free(fd->data); fd->data = NULL; - fd->freed = 1; } return read_byte; } @@ -213,7 +209,6 @@ jlong JNICALL fis_skip0_hook(JNIEnv *env, jobject thiz, jlong n) { if (skip == remaining) { free(fd->data); fd->data = NULL; - fd->freed = 1; return skip; } @@ -258,6 +253,5 @@ void JNICALL fis_close_hook(JNIEnv *env, jobject thiz) { free(file->value.data); file->value.data = NULL; - file->value.freed = 1; return; } \ No newline at end of file -- 2.47.3