diff options
| author | 2008-08-17 22:56:13 +0200 | |
|---|---|---|
| committer | 2008-08-21 19:13:35 +0200 | |
| commit | d5e52dbdfd46fd15e47e006590573902fcc3bbed (patch) | |
| tree | 9ae6c2af67a4e8bf5d59079fffe5238fad3fd9c7 | |
| parent | 89f0fd84b2c56e78c080ad4420b541eb8c96a9f2 (diff) | |
| download | libimobiledevice-d5e52dbdfd46fd15e47e006590573902fcc3bbed.tar.gz libimobiledevice-d5e52dbdfd46fd15e47e006590573902fcc3bbed.tar.bz2 | |
fix AFC memory leak and errors (from iphoneclient valgrind analysis).
| -rw-r--r-- | src/AFC.c | 13 | ||||
| -rw-r--r-- | src/main.c | 8 |
2 files changed, 14 insertions, 7 deletions
| @@ -239,6 +239,7 @@ static int receive_AFC_data(AFClient *client, char **dump_here) { | |||
| 239 | if(param1 == 0) { | 239 | if(param1 == 0) { |
| 240 | if (debug) fprintf(stderr, "... false alarm, but still\n"); | 240 | if (debug) fprintf(stderr, "... false alarm, but still\n"); |
| 241 | *dump_here = NULL; | 241 | *dump_here = NULL; |
| 242 | free(r_packet); | ||
| 242 | return 0; | 243 | return 0; |
| 243 | } | 244 | } |
| 244 | else { if (debug) fprintf(stderr, "Errno %i\n", param1); } | 245 | else { if (debug) fprintf(stderr, "Errno %i\n", param1); } |
| @@ -253,6 +254,7 @@ static int receive_AFC_data(AFClient *client, char **dump_here) { | |||
| 253 | if (!recv_len && r_packet->operation == AFC_SUCCESS_RESPONSE) | 254 | if (!recv_len && r_packet->operation == AFC_SUCCESS_RESPONSE) |
| 254 | { | 255 | { |
| 255 | *dump_here = NULL; | 256 | *dump_here = NULL; |
| 257 | free(r_packet); | ||
| 256 | return 0; | 258 | return 0; |
| 257 | } | 259 | } |
| 258 | 260 | ||
| @@ -272,7 +274,7 @@ static int receive_AFC_data(AFClient *client, char **dump_here) { | |||
| 272 | if(debug) fprintf(stderr, "receive_AFC_data: mux_recv delivered too much data\n"); | 274 | if(debug) fprintf(stderr, "receive_AFC_data: mux_recv delivered too much data\n"); |
| 273 | break; | 275 | break; |
| 274 | } | 276 | } |
| 275 | if (strstr(buffer, "CFA6LPAA")) { | 277 | if (bytes > 7 && strstr(buffer, "CFA6LPAA")) { |
| 276 | if (debug) fprintf(stderr, "receive_AFC_data: WARNING: there is AFC data in this packet at %ti\n", strstr(buffer, "CFA6LPAA") - buffer); | 278 | if (debug) fprintf(stderr, "receive_AFC_data: WARNING: there is AFC data in this packet at %ti\n", strstr(buffer, "CFA6LPAA") - buffer); |
| 277 | if (debug) fprintf(stderr, "receive_AFC_data: the total packet length is %i\n", bytes); | 279 | if (debug) fprintf(stderr, "receive_AFC_data: the total packet length is %i\n", bytes); |
| 278 | } | 280 | } |
| @@ -308,7 +310,7 @@ static char **make_strings_list(char *tokens, int true_length) { | |||
| 308 | list[i] = strdup(tokens+j); | 310 | list[i] = strdup(tokens+j); |
| 309 | j += strlen(list[i]) + 1; | 311 | j += strlen(list[i]) + 1; |
| 310 | } | 312 | } |
| 311 | list[i] = strdup(""); | 313 | list[i] = NULL; |
| 312 | 314 | ||
| 313 | return list; | 315 | return list; |
| 314 | } | 316 | } |
| @@ -455,6 +457,7 @@ int afc_rename_file(AFClient *client, const char *from, const char *to) { | |||
| 455 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 457 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| 456 | client->afc_packet->operation = AFC_RENAME; | 458 | client->afc_packet->operation = AFC_RENAME; |
| 457 | bytes = dispatch_AFC_packet(client, send, strlen(to) + strlen(from) + 2); | 459 | bytes = dispatch_AFC_packet(client, send, strlen(to) + strlen(from) + 2); |
| 460 | free(send); | ||
| 458 | if (bytes <= 0) { | 461 | if (bytes <= 0) { |
| 459 | afc_unlock(client); | 462 | afc_unlock(client); |
| 460 | return 0; | 463 | return 0; |
| @@ -547,7 +550,7 @@ AFCFile *afc_get_file_info(AFClient *client, const char *path) { | |||
| 547 | // Parse the data | 550 | // Parse the data |
| 548 | if (list) { | 551 | if (list) { |
| 549 | my_file = (AFCFile *)malloc(sizeof(AFCFile)); | 552 | my_file = (AFCFile *)malloc(sizeof(AFCFile)); |
| 550 | for (i = 0; strcmp(list[i], ""); i++) { | 553 | for (i = 0; list[i]; i++) { |
| 551 | if (!strcmp(list[i], "st_size")) { | 554 | if (!strcmp(list[i], "st_size")) { |
| 552 | my_file->size = atoi(list[i+1]); | 555 | my_file->size = atoi(list[i+1]); |
| 553 | } | 556 | } |
| @@ -564,7 +567,7 @@ AFCFile *afc_get_file_info(AFClient *client, const char *path) { | |||
| 564 | } | 567 | } |
| 565 | } | 568 | } |
| 566 | } | 569 | } |
| 567 | free_dictionary(list); | 570 | g_strfreev(list); |
| 568 | return my_file; | 571 | return my_file; |
| 569 | } else { | 572 | } else { |
| 570 | return NULL; | 573 | return NULL; |
| @@ -618,6 +621,7 @@ AFCFile *afc_open_file(AFClient *client, const char *filename, uint32 file_mode) | |||
| 618 | // Get the file info and return it | 621 | // Get the file info and return it |
| 619 | file_infos = afc_get_file_info(client, filename); | 622 | file_infos = afc_get_file_info(client, filename); |
| 620 | memcpy(&file_infos->filehandle, data, 4); | 623 | memcpy(&file_infos->filehandle, data, 4); |
| 624 | free(data); | ||
| 621 | return file_infos; | 625 | return file_infos; |
| 622 | } else { | 626 | } else { |
| 623 | if (debug) fprintf(stderr, "afc_open_file: Didn't get any further data\n"); | 627 | if (debug) fprintf(stderr, "afc_open_file: Didn't get any further data\n"); |
| @@ -661,6 +665,7 @@ int afc_read_file(AFClient *client, AFCFile *file, char *data, int length) { | |||
| 661 | client->afc_packet->operation = AFC_READ; | 665 | client->afc_packet->operation = AFC_READ; |
| 662 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 666 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| 663 | bytes = dispatch_AFC_packet(client, (char*)packet, sizeof(AFCFilePacket)); | 667 | bytes = dispatch_AFC_packet(client, (char*)packet, sizeof(AFCFilePacket)); |
| 668 | free(packet); | ||
| 664 | 669 | ||
| 665 | if (bytes <= 0) { | 670 | if (bytes <= 0) { |
| 666 | afc_unlock(client); | 671 | afc_unlock(client); |
| @@ -66,17 +66,18 @@ int main(int argc, char *argv[]) { | |||
| 66 | dirs = afc_get_dir_list(afc, "/eafaedf"); | 66 | dirs = afc_get_dir_list(afc, "/eafaedf"); |
| 67 | if (!dirs) dirs = afc_get_dir_list(afc, "/"); | 67 | if (!dirs) dirs = afc_get_dir_list(afc, "/"); |
| 68 | printf("Directory time.\n"); | 68 | printf("Directory time.\n"); |
| 69 | for (i = 0; strcmp(dirs[i], ""); i++) { | 69 | for (i = 0; dirs[i]; i++) { |
| 70 | printf("/%s\n", dirs[i]); | 70 | printf("/%s\n", dirs[i]); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | free_dictionary(dirs); | 73 | g_strfreev(dirs); |
| 74 | dirs = afc_get_devinfo(afc); | 74 | dirs = afc_get_devinfo(afc); |
| 75 | if (dirs) { | 75 | if (dirs) { |
| 76 | for (i = 0; strcmp(dirs[i], ""); i+=2) { | 76 | for (i = 0; dirs[i]; i+=2) { |
| 77 | printf("%s: %s\n", dirs[i], dirs[i+1]); | 77 | printf("%s: %s\n", dirs[i], dirs[i+1]); |
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| 80 | g_strfreev(dirs); | ||
| 80 | 81 | ||
| 81 | AFCFile *my_file = afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ); | 82 | AFCFile *my_file = afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ); |
| 82 | if (my_file) { | 83 | if (my_file) { |
| @@ -124,6 +125,7 @@ int main(int argc, char *argv[]) { | |||
| 124 | else printf("Couldn't read!\n"); | 125 | else printf("Couldn't read!\n"); |
| 125 | free(threeletterword); | 126 | free(threeletterword); |
| 126 | afc_close_file(afc, my_file); | 127 | afc_close_file(afc, my_file); |
| 128 | free(my_file); | ||
| 127 | 129 | ||
| 128 | } | 130 | } |
| 129 | afc_disconnect(afc); | 131 | afc_disconnect(afc); |
