Fix MapRead error callback being called with a valid pointer
This happened when a request resulted in an error while the buffer was already mapped. Adds a test that catches the error.
This commit is contained in:
parent
68358b5c23
commit
367cb3515c
|
@ -545,9 +545,12 @@ namespace wire {
|
||||||
}
|
}
|
||||||
buffer->mappedData = malloc(request.size);
|
buffer->mappedData = malloc(request.size);
|
||||||
memcpy(buffer->mappedData, cmd->GetData(), request.size);
|
memcpy(buffer->mappedData, cmd->GetData(), request.size);
|
||||||
}
|
|
||||||
|
|
||||||
request.callback(static_cast<nxtBufferMapReadStatus>(cmd->status), buffer->mappedData, request.userdata);
|
request.callback(static_cast<nxtBufferMapReadStatus>(cmd->status), buffer->mappedData, request.userdata);
|
||||||
|
} else {
|
||||||
|
request.callback(static_cast<nxtBufferMapReadStatus>(cmd->status), nullptr, request.userdata);
|
||||||
|
}
|
||||||
|
|
||||||
buffer->readRequests.erase(requestIt);
|
buffer->readRequests.erase(requestIt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -642,3 +642,39 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarly) {
|
||||||
// The callback shouldn't get called, even when the request succeeded on the server side
|
// The callback shouldn't get called, even when the request succeeded on the server side
|
||||||
FlushServer();
|
FlushServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that an error callback gets nullptr while a buffer is already mapped
|
||||||
|
TEST_F(WireBufferMappingTests, MappingErrorWhileAlreadyMappedGetsNullptr) {
|
||||||
|
// Successful map
|
||||||
|
nxtCallbackUserdata userdata = 34098;
|
||||||
|
nxtBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||||
|
|
||||||
|
uint32_t bufferContent = 31337;
|
||||||
|
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||||
|
.WillOnce(InvokeWithoutArgs([&]() {
|
||||||
|
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, &bufferContent);
|
||||||
|
}))
|
||||||
|
.RetiresOnSaturation();
|
||||||
|
|
||||||
|
FlushClient();
|
||||||
|
|
||||||
|
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
FlushServer();
|
||||||
|
|
||||||
|
// Map failure while the buffer is already mapped
|
||||||
|
userdata ++;
|
||||||
|
nxtBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||||
|
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||||
|
.WillOnce(InvokeWithoutArgs([&]() {
|
||||||
|
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr);
|
||||||
|
}));
|
||||||
|
|
||||||
|
FlushClient();
|
||||||
|
|
||||||
|
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
FlushServer();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue