diff options
| author | 2014-12-11 09:20:20 +0100 | |
|---|---|---|
| committer | 2015-01-12 15:51:09 +0100 | |
| commit | 1d9e6e351b51e7401898dde96418c0ee10ad878f (patch) | |
| tree | 3e7aebd142e5f8341d20494a07c4e8333f778599 /src/notification_proxy.c | |
| parent | ae637ea04cd63cb98587f9bb290b93c3a476d32b (diff) | |
| download | libimobiledevice-1d9e6e351b51e7401898dde96418c0ee10ad878f.tar.gz libimobiledevice-1d9e6e351b51e7401898dde96418c0ee10ad878f.tar.bz2 | |
Fix overlong blocking in np_client_free()
When using ideviceinstaller, np_client_free() would block for several
minutes when ideviceinstaller cleans up after installing the
application.
This happens because the function is blocking on thread_join(), waiting
for the notification watcher thread to finish. It only ends when
np_get_notification() returns a negative value after getting a timeout,
which takes several minutes.
However, the thread loop will also exit early if client->parent gets
NULL (the loop is iterated every 500ms), so this commit ensures
client->parent gets set to NULL early in np_client_free() so that
thread_join() does not block for a long time.
Signed-off-by: Martin Szulecki <m.szulecki@libimobiledevice.org>
Diffstat (limited to 'src/notification_proxy.c')
| -rw-r--r-- | src/notification_proxy.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/notification_proxy.c b/src/notification_proxy.c index dba42db..4b028f6 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c | |||
| @@ -114,6 +114,7 @@ LIBIMOBILEDEVICE_API np_error_t np_client_start_service(idevice_t device, np_cli | |||
| 114 | LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) | 114 | LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) |
| 115 | { | 115 | { |
| 116 | plist_t dict; | 116 | plist_t dict; |
| 117 | property_list_service_client_t parent; | ||
| 117 | 118 | ||
| 118 | if (!client) | 119 | if (!client) |
| 119 | return NP_E_INVALID_ARG; | 120 | return NP_E_INVALID_ARG; |
| @@ -123,12 +124,16 @@ LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) | |||
| 123 | property_list_service_send_xml_plist(client->parent, dict); | 124 | property_list_service_send_xml_plist(client->parent, dict); |
| 124 | plist_free(dict); | 125 | plist_free(dict); |
| 125 | 126 | ||
| 127 | parent = client->parent; | ||
| 128 | /* notifies the client->notifier thread that it should terminate */ | ||
| 129 | client->parent = NULL; | ||
| 130 | |||
| 126 | if (client->notifier) { | 131 | if (client->notifier) { |
| 127 | debug_info("joining np callback"); | 132 | debug_info("joining np callback"); |
| 128 | thread_join(client->notifier); | 133 | thread_join(client->notifier); |
| 129 | } else { | 134 | } else { |
| 130 | dict = NULL; | 135 | dict = NULL; |
| 131 | property_list_service_receive_plist(client->parent, &dict); | 136 | property_list_service_receive_plist(parent, &dict); |
| 132 | if (dict) { | 137 | if (dict) { |
| 133 | #ifndef STRIP_DEBUG_CODE | 138 | #ifndef STRIP_DEBUG_CODE |
| 134 | char *cmd_value = NULL; | 139 | char *cmd_value = NULL; |
| @@ -150,8 +155,7 @@ LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) | |||
| 150 | } | 155 | } |
| 151 | } | 156 | } |
| 152 | 157 | ||
| 153 | property_list_service_client_free(client->parent); | 158 | property_list_service_client_free(parent); |
| 154 | client->parent = NULL; | ||
| 155 | 159 | ||
| 156 | mutex_destroy(&client->mutex); | 160 | mutex_destroy(&client->mutex); |
| 157 | free(client); | 161 | free(client); |
