Surface: Initialize variable and add a defensive check

Initialize buf variable and make sure to check for return
value of dequeueBuffer() before sending to the client.

Change-Id: I0569f2d45825fab0e5d0f38fc91a07990f57c7ab
(cherry picked from commit a6bd7106a7305208f187fbf0a48f14139e33c9d6)
(cherry picked from commit e5d7662d68c5be2b282edd58d4feb68a4d476182)
(cherry picked from commit 885c146144480d4371a0a97df89b8e77f53d3d94)