   );
 
   THCudaCheck(cudaFree(stride_));
+  THCudaTensor_free(state, indices);
   THCudaTensor_free(state, src);
 }
 

void THCudaTensor_indexSelect(THCState *state, THCudaTensor *res_, THCudaTensor *src, int dim, THCudaTensor *indices)
{
  THAssert(THCudaTensor_checkGPU(state, 2, res_, src));
  THLongStorage *newSize;
  long *stride_;
  long nIndex = indices->size[0];
  long nRes;

  THArgCheck(indices->nDimension == 1, 3, "expecting vector of indices");
  THArgCheck(dim < src->nDimension, 4, "Indexing dim is out of bounds");

  THArgCheck(res_->nDimension > 0, 2, "Source tensor is empty");

  nRes = THCudaTensor_nElement(state, res_) / res_->size[dim] * nIndex;
  indices = THCudaTensor_newContiguous(state, indices);

  dim3 nthreads(16, 16);
  dim3 nblocks(ceil((float)nRes / nIndex / (16*16)));
