libsuperuser icon indicating copy to clipboard operation
libsuperuser copied to clipboard

OutOfMemoryError with Shell.SU.available()

Open ntoskrnl opened this issue 5 years ago • 1 comments

I am developing an app that requires root for some of its features. Users sometimes set up periodic tasks to run. It seems to wok fine on rooted devices, but if device is not rooted I sometimes get OutOfMemoryError.

Before running command via threaded shell instance obtained by Shell.Pool.get(), I check root availability via Shell.SU.available().

I can't tell for sure that your library is the root cause of the problem though, but almost all crashes happen during creation of HandlerThread for Shell instance. In addition, I tried to execute Shell.SU.available() in a loop (once every 10 seconds) and watch thread count in profiler. Each execution spawns a new thread and it is never terminated.

I am going to cache the result of Shell.SU.available() somewhere, but I think it is still something that is worth looking into.

ntoskrnl avatar Nov 20 '20 03:11 ntoskrnl

After further investigation, I invoke Shell.SU.available() through RxJava on Shcedulers.io() and it seems that this method never returns. I see the following lines in logcat:

...
D/libsuperuser: [libsuperuser][G][SU%] START
D/libsuperuser: [libsuperuser][P] newInstance(shell:su, pooled:1)
D/libsuperuser: [libsuperuser][G][SU%] START
D/libsuperuser: [libsuperuser][P] newInstance(shell:su, pooled:1)
D/libsuperuser: [libsuperuser][G][SU%] START
...

ntoskrnl avatar Nov 20 '20 03:11 ntoskrnl