Răsfoiți Sursa

Fix failure in test/inet/gethost_r-align:
we were closing a FILE, but did not record that fact by setting
a variable to NULL, and then we used it for reading!
While at it, small reduction in bss.
Run tested.

text data bss dec hex filename
- 210 0 12 222 de libc/inet/gethostent.o
+ 230 0 9 239 ef libc/inet/gethostent.o

Denis Vlasenko 17 ani în urmă
părinte
comite
c98a59e5a5
1 a modificat fișierele cu 8 adăugiri și 4 ștergeri
  1. 8 4
      libc/inet/resolv.c

+ 8 - 4
libc/inet/resolv.c

@@ -1721,22 +1721,24 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
 #ifdef L_gethostent
 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
 
-static int __stay_open;
+static smallint __stay_open;
 static FILE * __gethostent_fp;
 
 void endhostent(void)
 {
 	__UCLIBC_MUTEX_LOCK(mylock);
 	__stay_open = 0;
-	if (__gethostent_fp)
+	if (__gethostent_fp) {
 		fclose(__gethostent_fp);
+		__gethostent_fp = NULL;
+	}
 	__UCLIBC_MUTEX_UNLOCK(mylock);
 }
 
 void sethostent(int stay_open)
 {
 	__UCLIBC_MUTEX_LOCK(mylock);
-	__stay_open = stay_open;
+	__stay_open = (stay_open != 0);
 	__UCLIBC_MUTEX_UNLOCK(mylock);
 }
 
@@ -1757,8 +1759,10 @@ int gethostent_r(struct hostent *result_buf, char *buf, size_t buflen,
 
 	ret = __read_etc_hosts_r(__gethostent_fp, NULL, AF_INET, GETHOSTENT,
 		   result_buf, buf, buflen, result, h_errnop);
-	if (__stay_open == 0)
+	if (__stay_open == 0) {
 		fclose(__gethostent_fp);
+		__gethostent_fp = NULL;
+	}
 DONE:
 	__UCLIBC_MUTEX_UNLOCK(mylock);
 	return ret;