Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageProgressive crash: "pointer being freed was not allocated" #1449

Open
3 tasks done
joristimmerman opened this issue May 13, 2020 · 1 comment
Open
3 tasks done

Comments

@joristimmerman
Copy link

joristimmerman commented May 13, 2020

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

A common crash in our logs comes from this library. In production we currently have version 5.7.1, but the problems seems still to be in the latest version.

Taking a look at the code, I believe this is caused because the items array is being manipulated in one queue and read in another. Swift arrays are not thread safe.

Stacktrace

From version 5.7.1

0   libsystem_kernel.dylib          0x33776defc         __pthread_kill
1   libsystem_pthread.dylib         0x364c51d0c         pthread_kill
2   libsystem_c.dylib               0x1b0362a70         abort
3   libsystem_malloc.dylib          0x1b03c3f88         malloc_vreport
4   libsystem_malloc.dylib          0x1b03c4150         malloc_report
5   libsystem_malloc.dylib          0x1b03b80dc         free
6   libswiftCore.dylib              0x367b96c08         _swift_release_dealloc
7   libswiftCore.dylib              0x367b95a70         swift_release
8   libswiftDispatch.dylib          0x38e6dbaec         OS_dispatch_queue.init
9   Kingfisher                      0x105137b2c         ImageProgressiveSerialQueue.init (ImageProgressive.swift:265)
10  Kingfisher                      0x1051394f8         [inlined] init
11  Kingfisher                      0x1051394f8         ImageProgressiveProvider.init (ImageProgressive.swift:78)
12  Kingfisher                      0x105182050         [inlined] init
13  Kingfisher                      0x105182050         [inlined] init (ImageProgressive.swift:80)
14  Kingfisher                      0x105182050         KingfisherWrapper<T>.setImage (ImageView+Kingfisher.swift:113)
15  Kingfisher                      0x1051836b0         KingfisherWrapper<T>.setImage (ImageView+Kingfisher.swift:204)
16 ... our code calling setImage
@onevcat
Copy link
Owner

onevcat commented Jun 10, 2020

According to the log, the crash happens when initializing the ImageProgressiveProvider, and especially, when initializing a DispatchQueue value in ImageProgressiveSerialQueue. It should be totally a thread-safe behavior, and the problem is more likely under Swift or the system.

We could have a way to try to rewrite the code (such as adding an explicit initializer to ImageProgressiveSerialQueue), to see if we can work around it, but actually it should not be an issue in Kingfisher framework. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants