0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-12-04 18:45:52 +00:00
termux-packages/packages/jpegoptim/disable-fdsan.patch
Biswapriyo Nath 32b39deac2 fix(main/jpegoptim): Disable fdsan to fix running with multiple threads
This fixes the following runtime error.

jpegoptim -w6 image.jpg
image.jpg 512x512 24bit N JFIF [OK] 62476 --> 62476 bytes (0.00%), skipped.
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0x7d48447888
Aborted
2024-09-08 19:05:38 +05:30

30 lines
809 B
Diff

--- a/jpegoptim.c
+++ b/jpegoptim.c
@@ -1216,10 +1216,26 @@
}
#endif
+#include <android/fdsan.h>
+#include <dlfcn.h>
+
+static inline void termux_disable_fdsan() {
+ // For Android 11+.
+ void *lib_handle = dlopen("libc.so", RTLD_LAZY);
+ if (lib_handle) {
+ void (*set_fdsan_error_level)(enum android_fdsan_error_level newlevel) = dlsym(lib_handle, "android_fdsan_set_error_level");
+ if (set_fdsan_error_level) {
+ set_fdsan_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
+ }
+ dlclose(lib_handle);
+ }
+}
/****************************************************************************/
int main(int argc, char **argv)
{
+ termux_disable_fdsan();
+
struct stat file_stat;
char tmpfilename[MAXPATHLEN + 1],tmpdir[MAXPATHLEN + 1];
char newname[MAXPATHLEN + 1], dest_path[MAXPATHLEN + 1];