Skip to content

Commit cc8576a

Browse files
author
falkTX
committed
Check mmap() against MAP_FAILED
Fixes #338
1 parent 1aeb656 commit cc8576a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

linux/JackLinuxFutex.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ bool JackLinuxFutex::Allocate(const char* name, const char* server_name, int val
147147
return false;
148148
}
149149

150-
if ((fFutex = (FutexData*)mmap(NULL, sizeof(FutexData), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fSharedMem, 0)) == NULL) {
150+
FutexData* futex = (FutexData*)mmap(NULL, sizeof(FutexData), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fSharedMem, 0);
151+
152+
if (futex == NULL || futex == MAP_FAILED) {
151153
jack_error("Allocate: can't check in named futex name = %s err = %s", fName, strerror(errno));
152154
close(fSharedMem);
153155
fSharedMem = -1;
@@ -157,11 +159,12 @@ bool JackLinuxFutex::Allocate(const char* name, const char* server_name, int val
157159

158160
fPrivate = internal;
159161

160-
fFutex->futex = value;
161-
fFutex->internal = internal;
162-
fFutex->wasInternal = internal;
163-
fFutex->needsChange = false;
164-
fFutex->externalCount = 0;
162+
futex->futex = value;
163+
futex->internal = internal;
164+
futex->wasInternal = internal;
165+
futex->needsChange = false;
166+
futex->externalCount = 0;
167+
fFutex = futex;
165168
return true;
166169
}
167170

@@ -182,24 +185,27 @@ bool JackLinuxFutex::Connect(const char* name, const char* server_name)
182185
return false;
183186
}
184187

185-
if ((fFutex = (FutexData*)mmap(NULL, sizeof(FutexData), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fSharedMem, 0)) == NULL) {
188+
FutexData* futex = (FutexData*)mmap(NULL, sizeof(FutexData), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fSharedMem, 0);
189+
190+
if (futex == NULL || futex == MAP_FAILED) {
186191
jack_error("Connect: can't connect named futex name = %s err = %s", fName, strerror(errno));
187192
close(fSharedMem);
188193
fSharedMem = -1;
189194
return false;
190195
}
191196

192-
if (! fPrivate && fFutex->wasInternal)
197+
if (! fPrivate && futex->wasInternal)
193198
{
194199
const char* externalSync = getenv("JACK_INTERNAL_CLIENT_SYNC");
195200

196-
if (externalSync != NULL && strstr(fName, externalSync) != NULL && ++fFutex->externalCount == 1)
201+
if (externalSync != NULL && strstr(fName, externalSync) != NULL && ++futex->externalCount == 1)
197202
{
198203
jack_error("Note: client %s running as external client temporarily", fName);
199-
fFutex->needsChange = true;
204+
futex->needsChange = true;
200205
}
201206
}
202207

208+
fFutex = futex;
203209
return true;
204210
}
205211

0 commit comments

Comments
 (0)