summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Matt Colyer2008-08-07 00:00:12 -0700
committerGravatar Matt Colyer2008-08-07 00:00:12 -0700
commit4c3f86499f8dfe344fb5f92b805e8c090290a79e (patch)
treebba8b935df1b5ef637065e789a66f7b9fd2888f4 /src
parent1c6aa3dd8aa8cd985a63ccbfa3848ebbe52715e1 (diff)
downloadlibimobiledevice-4c3f86499f8dfe344fb5f92b805e8c090290a79e.tar.gz
libimobiledevice-4c3f86499f8dfe344fb5f92b805e8c090290a79e.tar.bz2
Added cleanup when closing a file, probably needs a bit more throughness
but its a start. Added a missing unlock call so you can read a file more than once.
Diffstat (limited to 'src')
-rw-r--r--src/AFC.c4
-rw-r--r--src/ifuse.c18
2 files changed, 19 insertions, 3 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 680a08f..6fb5a9e 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -423,9 +423,11 @@ int afc_read_file(AFClient *client, AFCFile *file, char *data, int length) {
bytes = receive_AFC_data(client, &input);
if (bytes < 0) {
if (input) free(input);
+ afc_unlock(client);
return -1;
} else if (bytes == 0) {
if (input) free(input);
+ afc_unlock(client);
return current_count;
} else {
if (input) {
@@ -493,6 +495,4 @@ void afc_close_file(AFClient *client, AFCFile *file) {
bytes = receive_AFC_data(client, &buffer);
afc_unlock(client);
return;
- if (buffer) free(buffer); // we're *SUPPOSED* to get an "error" here.
}
-
diff --git a/src/ifuse.c b/src/ifuse.c
index a56289d..3d921fd 100644
--- a/src/ifuse.c
+++ b/src/ifuse.c
@@ -112,10 +112,25 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset,
}
bytes = afc_read_file(afc, file, buf, size);
-
return bytes;
}
+static int ifuse_release(const char *path, struct fuse_file_info *fi){
+ AFCFile *file;
+ AFClient *afc = fuse_get_context()->private_data;
+
+ file = g_hash_table_lookup(file_handles, &(fi->fh));
+ if (!file){
+ return -ENOENT;
+ }
+ afc_close_file(afc, file);
+
+ free(file);
+ g_hash_table_remove(file_handles, &(fi->fh));
+
+ return 0;
+}
+
void *ifuse_init(struct fuse_conn_info *conn) {
char *response = (char*)malloc(sizeof(char) * 2048);
int bytes = 0, port = 0, i = 0;
@@ -171,6 +186,7 @@ static struct fuse_operations ifuse_oper = {
.readdir = ifuse_readdir,
.open = ifuse_open,
.read = ifuse_read,
+ .release = ifuse_release,
.init = ifuse_init,
.destroy = ifuse_cleanup
};