From 520dbc684721eb5d46af1ba87426c6f17e426235 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Fri, 13 Dec 2019 21:50:50 +0200 Subject: [PATCH] ndk-patches: avoid free()'ing pointer which is still in use --- ndk-patches/stdio.h.patch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ndk-patches/stdio.h.patch b/ndk-patches/stdio.h.patch index d4ed9cb28..9d276e4fd 100644 --- a/ndk-patches/stdio.h.patch +++ b/ndk-patches/stdio.h.patch @@ -1,6 +1,6 @@ -diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h ./usr/include/stdio.h ---- /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h 2017-11-09 09:57:12.000000000 +0100 -+++ ./usr/include/stdio.h 2017-11-15 11:57:58.567432093 +0100 +diff -uNr ./usr.old/include/stdio.h ./usr/include/stdio.h +--- ./usr.old/include/stdio.h 2019-05-22 12:49:28.000000000 +0300 ++++ ./usr/include/stdio.h 2019-12-13 21:50:02.765565736 +0200 @@ -44,11 +44,12 @@ #include #include @@ -53,7 +53,7 @@ diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h ./usr/incl FILE* fdopen(int __fd, const char* __mode); int fileno(FILE* __fp); -@@ -328,6 +332,29 @@ +@@ -328,6 +332,30 @@ #include #endif @@ -70,12 +70,13 @@ diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h ./usr/incl + unsigned int r = arc4random(); + if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL; + int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600); -+ free(path); + if (fd >= 0) { + FILE* result = fdopen(fd, "w+"); + unlink(path); ++ free(path); + return result; + } ++ free(path); + } + return NULL; +}