diff options
| author | 2008-08-07 00:00:12 -0700 | |
|---|---|---|
| committer | 2008-08-07 00:00:12 -0700 | |
| commit | 4c3f86499f8dfe344fb5f92b805e8c090290a79e (patch) | |
| tree | bba8b935df1b5ef637065e789a66f7b9fd2888f4 | |
| parent | 1c6aa3dd8aa8cd985a63ccbfa3848ebbe52715e1 (diff) | |
| download | libimobiledevice-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.
| -rw-r--r-- | src/AFC.c | 4 | ||||
| -rw-r--r-- | src/ifuse.c | 18 |
2 files changed, 19 insertions, 3 deletions
| @@ -423,9 +423,11 @@ int afc_read_file(AFClient *client, AFCFile *file, char *data, int length) { | |||
| 423 | bytes = receive_AFC_data(client, &input); | 423 | bytes = receive_AFC_data(client, &input); |
| 424 | if (bytes < 0) { | 424 | if (bytes < 0) { |
| 425 | if (input) free(input); | 425 | if (input) free(input); |
| 426 | afc_unlock(client); | ||
| 426 | return -1; | 427 | return -1; |
| 427 | } else if (bytes == 0) { | 428 | } else if (bytes == 0) { |
| 428 | if (input) free(input); | 429 | if (input) free(input); |
| 430 | afc_unlock(client); | ||
| 429 | return current_count; | 431 | return current_count; |
| 430 | } else { | 432 | } else { |
| 431 | if (input) { | 433 | if (input) { |
| @@ -493,6 +495,4 @@ void afc_close_file(AFClient *client, AFCFile *file) { | |||
| 493 | bytes = receive_AFC_data(client, &buffer); | 495 | bytes = receive_AFC_data(client, &buffer); |
| 494 | afc_unlock(client); | 496 | afc_unlock(client); |
| 495 | return; | 497 | return; |
| 496 | if (buffer) free(buffer); // we're *SUPPOSED* to get an "error" here. | ||
| 497 | } | 498 | } |
| 498 | |||
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, | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | bytes = afc_read_file(afc, file, buf, size); | 114 | bytes = afc_read_file(afc, file, buf, size); |
| 115 | |||
| 116 | return bytes; | 115 | return bytes; |
| 117 | } | 116 | } |
| 118 | 117 | ||
| 118 | static int ifuse_release(const char *path, struct fuse_file_info *fi){ | ||
| 119 | AFCFile *file; | ||
| 120 | AFClient *afc = fuse_get_context()->private_data; | ||
| 121 | |||
| 122 | file = g_hash_table_lookup(file_handles, &(fi->fh)); | ||
| 123 | if (!file){ | ||
| 124 | return -ENOENT; | ||
| 125 | } | ||
| 126 | afc_close_file(afc, file); | ||
| 127 | |||
| 128 | free(file); | ||
| 129 | g_hash_table_remove(file_handles, &(fi->fh)); | ||
| 130 | |||
| 131 | return 0; | ||
| 132 | } | ||
| 133 | |||
| 119 | void *ifuse_init(struct fuse_conn_info *conn) { | 134 | void *ifuse_init(struct fuse_conn_info *conn) { |
| 120 | char *response = (char*)malloc(sizeof(char) * 2048); | 135 | char *response = (char*)malloc(sizeof(char) * 2048); |
| 121 | int bytes = 0, port = 0, i = 0; | 136 | int bytes = 0, port = 0, i = 0; |
| @@ -171,6 +186,7 @@ static struct fuse_operations ifuse_oper = { | |||
| 171 | .readdir = ifuse_readdir, | 186 | .readdir = ifuse_readdir, |
| 172 | .open = ifuse_open, | 187 | .open = ifuse_open, |
| 173 | .read = ifuse_read, | 188 | .read = ifuse_read, |
| 189 | .release = ifuse_release, | ||
| 174 | .init = ifuse_init, | 190 | .init = ifuse_init, |
| 175 | .destroy = ifuse_cleanup | 191 | .destroy = ifuse_cleanup |
| 176 | }; | 192 | }; |
