Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
yh_sdwebimage
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Joshua Feldman
8 years ago
Commit
1f33e95aa61da6c1021031d1e6057160c6c836f2
1 parent
041842bf
#1807 - #1821 - Fixing incorrectly retained pointer to self which appears to cre…
…ate a dangled pointer
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
SDWebImage/SDWebImageDownloaderOperation.m
SDWebImage/SDWebImageDownloaderOperation.m
View file @
1f33e95
...
...
@@ -169,8 +169,9 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
for
(
SDWebImageDownloaderProgressBlock
progressBlock
in
[
self
callbacksForKey
:
kProgressCallbackKey
])
{
progressBlock
(
0
,
NSURLResponseUnknownLength
,
self
.
request
.
URL
);
}
__weak
typeof
(
self
)
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStartNotification
object
:
s
elf
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStartNotification
object
:
weakS
elf
];
});
}
else
{
[
self
callCompletionBlocksWithError
:[
NSError
errorWithDomain
:
NSURLErrorDomain
code
:
0
userInfo
:
@
{
NSLocalizedDescriptionKey
:
@"Connection can't be initialized"
}]];
...
...
@@ -201,8 +202,9 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
if
(
self
.
dataTask
)
{
[
self
.
dataTask
cancel
];
__weak
typeof
(
self
)
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStopNotification
object
:
s
elf
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStopNotification
object
:
weakS
elf
];
});
// As we cancelled the connection, its callback won't be called and thus won't
...
...
@@ -266,8 +268,9 @@ didReceiveResponse:(NSURLResponse *)response
self
.
imageData
=
[[
NSMutableData
alloc
]
initWithCapacity
:
expected
];
self
.
response
=
response
;
__weak
typeof
(
self
)
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadReceiveResponseNotification
object
:
s
elf
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadReceiveResponseNotification
object
:
weakS
elf
];
});
}
else
{
...
...
@@ -280,8 +283,9 @@ didReceiveResponse:(NSURLResponse *)response
}
else
{
[
self
.
dataTask
cancel
];
}
__weak
typeof
(
self
)
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStopNotification
object
:
s
elf
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStopNotification
object
:
weakS
elf
];
});
[
self
callCompletionBlocksWithError
:[
NSError
errorWithDomain
:
NSURLErrorDomain
code
:((
NSHTTPURLResponse
*
)
response
).
statusCode
userInfo
:
nil
]];
...
...
@@ -402,10 +406,11 @@ didReceiveResponse:(NSURLResponse *)response
-
(
void
)
URLSession
:
(
NSURLSession
*
)
session
task
:
(
NSURLSessionTask
*
)
task
didCompleteWithError
:
(
NSError
*
)
error
{
@synchronized
(
self
)
{
self
.
dataTask
=
nil
;
__weak
typeof
(
self
)
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStopNotification
object
:
s
elf
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadStopNotification
object
:
weakS
elf
];
if
(
!
error
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadFinishNotification
object
:
s
elf
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
SDWebImageDownloadFinishNotification
object
:
weakS
elf
];
}
});
}
...
...
Please
register
or
login
to post a comment