[mlir][sparse] fix broken asan test
authorAart Bik <ajcbik@google.com>
Fri, 29 Oct 2021 03:36:29 +0000 (20:36 -0700)
committerAart Bik <ajcbik@google.com>
Fri, 29 Oct 2021 03:53:58 +0000 (20:53 -0700)
TBR : delete was dropped from previous approved revision (https://reviews.llvm.org/D110790), breaking asan

Differential Revision: https://reviews.llvm.org/D112779

mlir/lib/ExecutionEngine/SparseUtils.cpp

index 0b82378..d193e80 100644 (file)
@@ -635,16 +635,18 @@ enum Action : uint32_t {
   }
 
 #define IMPL_GETNEXT(NAME, V)                                                  \
-  bool _mlir_ciface_##NAME(void *ptr, StridedMemRefType<uint64_t, 1> *iref,    \
+  bool _mlir_ciface_##NAME(void *tensor, StridedMemRefType<uint64_t, 1> *iref, \
                            StridedMemRefType<V, 0> *vref) {                    \
     assert(iref->strides[0] == 1);                                             \
     uint64_t *indx = iref->data + iref->offset;                                \
     V *value = vref->data + vref->offset;                                      \
     const uint64_t isize = iref->sizes[0];                                     \
-    auto iter = static_cast<SparseTensorCOO<V> *>(ptr);                        \
+    auto iter = static_cast<SparseTensorCOO<V> *>(tensor);                     \
     const Element<V> *elem = iter->getNext();                                  \
-    if (elem == nullptr)                                                       \
+    if (elem == nullptr) {                                                     \
+      delete iter;                                                             \
       return false;                                                            \
+    }                                                                          \
     for (uint64_t r = 0; r < isize; r++)                                       \
       indx[r] = elem->indices[r];                                              \
     *value = elem->value;                                                      \