@@ -165,51 +165,38 @@ lockdownd_error_t lockdown_check_result(plist_t dict, const char *query_match)
165165 return ret ;
166166 }
167167
168- char * query_value = NULL ;
169-
170- plist_get_string_val (query_node , & query_value );
168+ const char * query_value = plist_get_string_ptr (query_node , NULL );
171169 if (!query_value ) {
172170 return ret ;
173171 }
174172
175173 if (query_match && (strcmp (query_value , query_match ) != 0 )) {
176- free (query_value );
177174 return ret ;
178175 }
179176
180- free (query_value );
181-
182- plist_t result_node = plist_dict_get_item (dict , "Result" );
183- if (!result_node ) {
184- /* iOS 5: the 'Result' key is not present anymore.
185- But we need to check for the 'Error' key. */
186- plist_t err_node = plist_dict_get_item (dict , "Error" );
187- if (err_node ) {
188- if (plist_get_node_type (err_node ) == PLIST_STRING ) {
189- char * err_value = NULL ;
190-
191- plist_get_string_val (err_node , & err_value );
192- if (err_value ) {
193- debug_info ("ERROR: %s" , err_value );
194- ret = lockdownd_strtoerr (err_value );
195- free (err_value );
196- } else {
197- debug_info ("ERROR: unknown error occurred" );
198- }
177+ /* Check for 'Error' in reply */
178+ plist_t err_node = plist_dict_get_item (dict , "Error" );
179+ if (err_node ) {
180+ if (plist_get_node_type (err_node ) == PLIST_STRING ) {
181+ const char * err_value = plist_get_string_ptr (err_node , NULL );
182+ if (err_value ) {
183+ debug_info ("ERROR: %s" , err_value );
184+ ret = lockdownd_strtoerr (err_value );
185+ } else {
186+ debug_info ("ERROR: unknown error occurred" );
199187 }
200- return ret ;
201188 }
202-
203- ret = LOCKDOWN_E_SUCCESS ;
204-
205189 return ret ;
206190 }
207191
208- plist_type result_type = plist_get_node_type (result_node );
209- if (result_type == PLIST_STRING ) {
210- char * result_value = NULL ;
211-
212- plist_get_string_val (result_node , & result_value );
192+ plist_t result_node = plist_dict_get_item (dict , "Result" );
193+ if (!result_node ) {
194+ /* With iOS 5+ 'Result' is not present anymore.
195+ If there is no 'Error', we can just assume success. */
196+ return LOCKDOWN_E_SUCCESS ;
197+ }
198+ if (plist_get_node_type (result_node ) == PLIST_STRING ) {
199+ const char * result_value = plist_get_string_ptr (result_node , NULL );
213200 if (result_value ) {
214201 if (!strcmp (result_value , "Success" )) {
215202 ret = LOCKDOWN_E_SUCCESS ;
@@ -219,9 +206,6 @@ lockdownd_error_t lockdown_check_result(plist_t dict, const char *query_match)
219206 debug_info ("ERROR: unknown result value '%s'" , result_value );
220207 }
221208 }
222-
223- if (result_value )
224- free (result_value );
225209 }
226210
227211 return ret ;
0 commit comments