Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(809)

Unified Diff: newlib/libc/stdio/findfp.c

Issue 7604003: Fix race condition in concurrent printf and fopen. (Closed) Base URL: http://git.chromium.org/native_client/nacl-newlib.git@master
Patch Set: emailing Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: newlib/libc/stdio/findfp.c
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 6e5873ffe3dfdd57e5b1810d74911b65a660bd3e..56c143d209e50ed5a004c4f26f1d8942e17f4dbd 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -107,6 +107,7 @@ _DEFUN(__sfp, (d),
FILE *fp;
int n;
struct _glue *g;
+ int found_fp = 0;
CHECK_INIT(_GLOBAL_REENT, NULL);
@@ -115,8 +116,13 @@ _DEFUN(__sfp, (d),
for (g = &_GLOBAL_REENT->__sglue;; g = g->_next)
{
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
- if (fp->_flags == 0)
- goto found;
+ {
+ _flockfile(fp);
+ found_fp = (fp->_flags == 0);
+ _funlockfile(fp);
+ if (found_fp)
+ goto found;
+ }
if (g->_next == NULL &&
(g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL)
break;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698