tv-casting-app: fix TargetVideoPlayerInfo mem corruption #257
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The IPAddress and MACAddress fields (in the TargetVideoPlayerInfo), required for the WakeOnLAN implementation, were sometimes getting corrupted when the VerifyOrEstablishConnectionTask() API is called. This was because the VerifyOrEstablishConnection() API gets a reference to the targetVideoPlayerInfo that is created on the stack by the caller. If we copy the input param targetVideoPlayerInfo to the mActiveTargetVideoPlayerInfo, the underlying memory for the IPAddress and MACAddress may get deallocated as the original targetVideoPlayerInfo goes out of scope of the caller.
Solution
Find the index of the targetVideoPlayerInfo in the mCachedTargetVideoPlayerInfo array that is held in the CastingServer class as a data member. Then copy the cached equivalent of the targetVideoPlayerInfo to mActiveTargetVideoPlayerInfo. This way the memory locations the mActiveTargetVideoPlayerInfo stays valid during a connection attempt, as the mCachedTargetVideoPlayerInfo[] is a CastingServer class data member.
Testing
Tested using the android tv-casting-app running against the Linux tv-app and checked that the IP Address and MAC Address fields now stay valid.