ndk-patches: avoid free()'ing pointer which is still in use

This commit is contained in:
Leonid Pliushch 2019-12-13 21:50:50 +02:00
parent 5d0a8a8045
commit 520dbc6847

View File

@ -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 <stdarg.h>
#include <stddef.h>
@ -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 <bits/fortify/stdio.h>
#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;
+}