Remove freed variable from data structs #4

Merged
SKBotNL merged 1 commits from main into main 2026-04-05 13:10:58 -04:00
2 changed files with 3 additions and 13 deletions

No files matched your search

+1 -5
View File
@@ -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;
}
+2 -8
View File
@@ -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;
}