Skip to content

Commit a1ff39f

Browse files
committed
backport relevant part from bug #72858 patch in 7.0
1 parent 6a232c3 commit a1ff39f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

TSRM/tsrm_win32.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,17 +654,27 @@ TSRM_API int shmget(int key, int size, int flags)
654654
TSRM_API void *shmat(int key, const void *shmaddr, int flags)
655655
{
656656
shm_pair *shm = shm_get(key, NULL);
657+
int err;
657658

658659
if (!shm->segment) {
659660
return (void*)-1;
660661
}
661662

663+
shm->addr = MapViewOfFileEx(shm->segment, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
664+
665+
err = GetLastError();
666+
if (err) {
667+
/* Catch more errors */
668+
if (ERROR_NOT_ENOUGH_MEMORY == err) {
669+
_set_errno(ENOMEM);
670+
}
671+
return (void*)-1;
672+
}
673+
662674
shm->descriptor->shm_atime = time(NULL);
663675
shm->descriptor->shm_lpid = getpid();
664676
shm->descriptor->shm_nattch++;
665677

666-
shm->addr = MapViewOfFileEx(shm->segment, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
667-
668678
return shm->addr;
669679
}
670680

0 commit comments

Comments
 (0)