diff options
| author | 2014-08-18 16:56:15 -0400 | |
|---|---|---|
| committer | 2014-08-22 07:33:45 +0200 | |
| commit | e02b675d265d9be3abccbd3b730bb7dffbf811e3 (patch) | |
| tree | 554150181cfccde28733ef624be9ec7614677830 /src | |
| parent | 0e16e0a1ddeca038bb00b1dd6f1fb799a47e4b7f (diff) | |
| download | libimobiledevice-e02b675d265d9be3abccbd3b730bb7dffbf811e3.tar.gz libimobiledevice-e02b675d265d9be3abccbd3b730bb7dffbf811e3.tar.bz2 | |
afc_file_open: fixed memory leak when the object is not found or arguments are invalid.
Diffstat (limited to 'src')
| -rw-r--r-- | src/afc.c | 9 |
1 files changed, 6 insertions, 3 deletions
| @@ -616,6 +616,9 @@ idevice_error_t | |||
| 616 | afc_file_open(afc_client_t client, const char *filename, | 616 | afc_file_open(afc_client_t client, const char *filename, |
| 617 | afc_file_mode_t file_mode, uint64_t *handle) | 617 | afc_file_mode_t file_mode, uint64_t *handle) |
| 618 | { | 618 | { |
| 619 | if (!client || !client->parent || !client->afc_packet) | ||
| 620 | return AFC_E_INVALID_ARG; | ||
| 621 | |||
| 619 | uint64_t file_mode_loc = htole64(file_mode); | 622 | uint64_t file_mode_loc = htole64(file_mode); |
| 620 | uint32_t bytes = 0; | 623 | uint32_t bytes = 0; |
| 621 | char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); | 624 | char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); |
| @@ -624,9 +627,6 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 624 | /* set handle to 0 so in case an error occurs, the handle is invalid */ | 627 | /* set handle to 0 so in case an error occurs, the handle is invalid */ |
| 625 | *handle = 0; | 628 | *handle = 0; |
| 626 | 629 | ||
| 627 | if (!client || !client->parent || !client->afc_packet) | ||
| 628 | return AFC_E_INVALID_ARG; | ||
| 629 | |||
| 630 | afc_lock(client); | 630 | afc_lock(client); |
| 631 | 631 | ||
| 632 | /* Send command */ | 632 | /* Send command */ |
| @@ -642,6 +642,7 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 642 | return AFC_E_NOT_ENOUGH_DATA; | 642 | return AFC_E_NOT_ENOUGH_DATA; |
| 643 | } | 643 | } |
| 644 | /* Receive the data */ | 644 | /* Receive the data */ |
| 645 | data = NULL; | ||
| 645 | ret = afc_receive_data(client, &data, &bytes); | 646 | ret = afc_receive_data(client, &data, &bytes); |
| 646 | if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { | 647 | if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { |
| 647 | afc_unlock(client); | 648 | afc_unlock(client); |
| @@ -651,6 +652,8 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 651 | free(data); | 652 | free(data); |
| 652 | return ret; | 653 | return ret; |
| 653 | } | 654 | } |
| 655 | /* in case memory was allocated but no data received or an error occurred */ | ||
| 656 | free(data); | ||
| 654 | 657 | ||
| 655 | debug_info("Didn't get any further data"); | 658 | debug_info("Didn't get any further data"); |
| 656 | 659 | ||
