From ac0314e07ab5e0701248fd1925bc5a370b2ccde9 Mon Sep 17 00:00:00 2001 From: samdmarshall Date: Sun, 23 Nov 2014 12:44:41 -0500 Subject: [PATCH] adding back code to close socket on invalid connection --- .gitignore | 4 ++- .../Connection/SDMMD_Connection.c | 20 +++++------ .../Services/Debugger/SDMMD_Debugger.c | 6 +++- .../project.pbxproj | 2 +- .../xcshareddata/SDMMobileDevice.xccheckout | 34 ++++++++++++++++--- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 8762ee6..d5e6474 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ build/ xcuserdata SDMMobileDevice.xcworkspace/xcuserdata/ SDMMobileDevice.podspec -podspec \ No newline at end of file +podspec +*/*.xcodeproj/xcshareddata +SDMMobileDevice.xcworkspace/xcshareddata diff --git a/Framework/MobileDevice/Connection/SDMMD_Connection.c b/Framework/MobileDevice/Connection/SDMMD_Connection.c index a6ef630..dbc0c4e 100644 --- a/Framework/MobileDevice/Connection/SDMMD_Connection.c +++ b/Framework/MobileDevice/Connection/SDMMD_Connection.c @@ -400,12 +400,12 @@ sdmmd_return_t SDMMD_AMDeviceSecureStartService(SDMMD_AMDeviceRef device, CFStri sdmmd_return_t SDMMD_AMDeviceStartService(SDMMD_AMDeviceRef device, CFStringRef service, CFDictionaryRef options, SDMMD_AMConnectionRef *connection) { sdmmd_return_t result = kAMDInvalidArgumentError; - //uint32_t socket = -1; + uint32_t tmp_socket = -1, socket = -1; if (device && connection) { SSL *ssl_enabled = NULL; if (service) { if (device->ivars.device_active) { - CFMutableDictionaryRef optionsCopy; + CFMutableDictionaryRef optionsCopy = NULL; if (options) { optionsCopy = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, options); } @@ -417,10 +417,11 @@ sdmmd_return_t SDMMD_AMDeviceStartService(SDMMD_AMDeviceRef device, CFStringRef result = SDMMD_AMDeviceSecureStartService(device, service, optionsCopy, connection); CFSafeRelease(optionsCopy); if (result == 0) { - //socket = SDMMD_AMDServiceConnectionGetSocket(*connection); + socket = SDMMD_AMDServiceConnectionGetSocket(*connection); ssl_enabled = SDMMD_AMDServiceConnectionGetSecureIOContext(*connection); if (ssl_enabled) { result = kAMDNoWifiSyncSupportError; + tmp_socket = socket; } else { result = kAMDSuccess; @@ -436,15 +437,14 @@ sdmmd_return_t SDMMD_AMDeviceStartService(SDMMD_AMDeviceRef device, CFStringRef ssl_enabled = NULL; } } - /*if (ssl_enabled) + if (ssl_enabled) { SSL_free(ssl_enabled); - if (socket != 0xff) { - if(close(socket) == 0xff) { - printf("SDMMD_AMDeviceStartService: close(2) con socket %d failed: %d\n",socket,errno); - } - }*/ + } + if (tmp_socket != -1 && close(tmp_socket) == -1) { + printf("%s: close(2) con socket %d failed: %d\n",__FUNCTION__, tmp_socket,errno); + } } - //printf("SDMMD_AMDeviceStartService: returning 0x%x, socket is %d.\n",result, socket); + //printf("%s: returning 0x%x, socket is %d.\n",__FUNCTION__, result, socket); return result; } diff --git a/Framework/MobileDevice/Services/Debugger/SDMMD_Debugger.c b/Framework/MobileDevice/Services/Debugger/SDMMD_Debugger.c index 6a0c4fa..5fede48 100644 --- a/Framework/MobileDevice/Services/Debugger/SDMMD_Debugger.c +++ b/Framework/MobileDevice/Services/Debugger/SDMMD_Debugger.c @@ -82,6 +82,7 @@ sdmmd_return_t SDMMD_AMDebugConnectionStart(SDMMD_AMDebugConnectionRef dconn) { dconn->connection = SDMMD_AMDServiceConnectionCreate(0, NULL, NULL); result = SDMMD_AMDeviceStartService(dconn->device, CFSTR(AMSVC_DEBUG_SERVER), NULL, &(dconn->connection)); + CheckErrorAndReturn(result); result = SDMMD_AMDeviceStopSession(dconn->device); CheckErrorAndReturn(result); @@ -167,7 +168,10 @@ sdmmd_return_t SDMMD__hangup_with_image_mounter_service(SDMMD_AMConnectionRef co result = SDMMD_ServiceReceiveMessage(socket, &response); PrintCFDictionary(response); } - ExitLabelAndReturn(result); + +ExitLabel: + CFSafeRelease(dict); + return result; } CFStringRef SDMMD_CopyDeviceSupportPathFromXCRUN() { diff --git a/Framework/SDMMobileDevice-Framework.xcodeproj/project.pbxproj b/Framework/SDMMobileDevice-Framework.xcodeproj/project.pbxproj index 066b87e..c49b464 100644 --- a/Framework/SDMMobileDevice-Framework.xcodeproj/project.pbxproj +++ b/Framework/SDMMobileDevice-Framework.xcodeproj/project.pbxproj @@ -597,8 +597,8 @@ 22DEF962188350E6008E909F /* CoreFoundation */ = { isa = PBXGroup; children = ( - 22A58E1C191157F600303D31 /* CFStringAddition.c */, 22A58E1D191157F600303D31 /* CFStringAddition.h */, + 22A58E1C191157F600303D31 /* CFStringAddition.c */, 22C892AA189D75A1008B1D2D /* CFDataAddition.h */, 22C892A9189D75A1008B1D2D /* CFDataAddition.c */, 22DEF964188350E6008E909F /* CFDictionaryAddition.h */, diff --git a/SDMMobileDevice.xcworkspace/xcshareddata/SDMMobileDevice.xccheckout b/SDMMobileDevice.xcworkspace/xcshareddata/SDMMobileDevice.xccheckout index 26444bb..38003c0 100644 --- a/SDMMobileDevice.xcworkspace/xcshareddata/SDMMobileDevice.xccheckout +++ b/SDMMobileDevice.xcworkspace/xcshareddata/SDMMobileDevice.xccheckout @@ -10,30 +10,38 @@ SDMMobileDevice IDESourceControlProjectOriginsDictionary + 5DC493081D5ABCA9EA77A520F32861D07A12B20C + github.com:samdmarshall/SDMMobileDevice.git 69DB9D35-4562-46FC-9ADE-37339C753AA0 ssh://github.com/samdmarshall/Core-Lib.git E03DDEF6-B97D-41E3-B129-83B8A6249CEB ssh://github.com/samdmarshall/SDMMobileDevice.git E3836662-8199-4399-9034-FC52A1A354C7 ssh://github.com/samdmarshall/Macro-Utilities.git + F09F31DD51BF51244351F594DC43B25CE185FB38 + github.com:samdmarshall/Core-Lib.git IDESourceControlProjectPath SDMMobileDevice.xcworkspace IDESourceControlProjectRelativeInstallPathDictionary + 5DC493081D5ABCA9EA77A520F32861D07A12B20C + .. 69DB9D35-4562-46FC-9ADE-37339C753AA0 - ../Core + ../../SDM_MD_Demo/Core E03DDEF6-B97D-41E3-B129-83B8A6249CEB - .. + ../../SDM_MD_Demo E3836662-8199-4399-9034-FC52A1A354C7 ../../Macro Utilities + F09F31DD51BF51244351F594DC43B25CE185FB38 + ..Core IDESourceControlProjectURL - ssh://github.com/samdmarshall/SDMMobileDevice.git + github.com:samdmarshall/SDMMobileDevice.git IDESourceControlProjectVersion - 110 + 111 IDESourceControlProjectWCCIdentifier - E03DDEF6-B97D-41E3-B129-83B8A6249CEB + 5DC493081D5ABCA9EA77A520F32861D07A12B20C IDESourceControlProjectWCConfigurations @@ -60,6 +68,22 @@ IDESourceControlWCCName SDM_MD_Demo + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + 5DC493081D5ABCA9EA77A520F32861D07A12B20C + IDESourceControlWCCName + SDMMobileDevice + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + F09F31DD51BF51244351F594DC43B25CE185FB38 + IDESourceControlWCCName + SDMMobileDeviceCore +