* posix_ipc.cc (mq_open): Avoid closing the same descriptor twice in
case of errors. (sem_open): Ditto.
This commit is contained in:
		| @@ -1,3 +1,9 @@ | |||||||
|  | 2009-09-24  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* posix_ipc.cc (mq_open): Avoid closing the same descriptor twice in | ||||||
|  | 	case of errors. | ||||||
|  | 	(sem_open): Ditto. | ||||||
|  |  | ||||||
| 2009-09-24  Corinna Vinschen  <corinna@vinschen.de> | 2009-09-24  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* kernel32.cc (CreateMutexW): Use correct access mask. | 	* kernel32.cc (CreateMutexW): Use correct access mask. | ||||||
|   | |||||||
| @@ -312,7 +312,7 @@ extern "C" void *mmap64 (void *, size_t, int, int, int, _off64_t); | |||||||
| extern "C" mqd_t | extern "C" mqd_t | ||||||
| mq_open (const char *name, int oflag, ...) | mq_open (const char *name, int oflag, ...) | ||||||
| { | { | ||||||
|   int i, fd, nonblock, created; |   int i, fd = -1, nonblock, created; | ||||||
|   long msgsize, index; |   long msgsize, index; | ||||||
|   _off64_t filesize = 0; |   _off64_t filesize = 0; | ||||||
|   va_list ap; |   va_list ap; | ||||||
| @@ -449,6 +449,7 @@ exists: | |||||||
| 	  if (errno == ENOENT && (oflag & O_CREAT)) | 	  if (errno == ENOENT && (oflag & O_CREAT)) | ||||||
| 	    { | 	    { | ||||||
| 	      close (fd); | 	      close (fd); | ||||||
|  | 	      fd = -1; | ||||||
| 	      goto again; | 	      goto again; | ||||||
| 	    } | 	    } | ||||||
| 	  goto err; | 	  goto err; | ||||||
| @@ -469,6 +470,7 @@ exists: | |||||||
|   if (mptr == (int8_t *) MAP_FAILED) |   if (mptr == (int8_t *) MAP_FAILED) | ||||||
|     goto err; |     goto err; | ||||||
|   close (fd); |   close (fd); | ||||||
|  |   fd = -1; | ||||||
|  |  | ||||||
|   /* Allocate one mq_info{} for each open */ |   /* Allocate one mq_info{} for each open */ | ||||||
|   if (!(mqinfo = (struct mq_info *) malloc (sizeof (struct mq_info)))) |   if (!(mqinfo = (struct mq_info *) malloc (sizeof (struct mq_info)))) | ||||||
| @@ -500,7 +502,8 @@ err: | |||||||
|     munmap((void *) mptr, (size_t) filesize); |     munmap((void *) mptr, (size_t) filesize); | ||||||
|   if (mqinfo) |   if (mqinfo) | ||||||
|     free (mqinfo); |     free (mqinfo); | ||||||
|   close (fd); |   if (fd >= 0) | ||||||
|  |     close (fd); | ||||||
|   return (mqd_t) -1; |   return (mqd_t) -1; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -909,7 +912,7 @@ struct sem_finfo | |||||||
| extern "C" sem_t * | extern "C" sem_t * | ||||||
| sem_open (const char *name, int oflag, ...) | sem_open (const char *name, int oflag, ...) | ||||||
| { | { | ||||||
|   int i, fd, created; |   int i, fd = -1, created; | ||||||
|   va_list ap; |   va_list ap; | ||||||
|   mode_t mode = 0; |   mode_t mode = 0; | ||||||
|   unsigned int value = 0; |   unsigned int value = 0; | ||||||
| @@ -985,6 +988,7 @@ exists: | |||||||
| 	  if (errno == ENOENT && (oflag & O_CREAT)) | 	  if (errno == ENOENT && (oflag & O_CREAT)) | ||||||
| 	    { | 	    { | ||||||
| 	      close (fd); | 	      close (fd); | ||||||
|  | 	      fd = -1; | ||||||
| 	      goto again; | 	      goto again; | ||||||
| 	    } | 	    } | ||||||
| 	  goto err; | 	  goto err; | ||||||
| @@ -1023,7 +1027,8 @@ err: | |||||||
|     unlink (semname); |     unlink (semname); | ||||||
|   if (sem != SEM_FAILED) |   if (sem != SEM_FAILED) | ||||||
|     semaphore::close (sem); |     semaphore::close (sem); | ||||||
|   close (fd); |   if (fd >= 0) | ||||||
|  |     close (fd); | ||||||
|   return SEM_FAILED; |   return SEM_FAILED; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user