Coverity reports a resource leak here. When we return due to invalid
selection, we should free the 'ldata' that we previously allocated
Fixes Coverity CID1396998
ldata is not needed until the end of the function pretty much. I think that moving its allocation to later in the function would actually solve the issue here.
Move ldata allocation to end of function where it is needed, based on