diff --git a/backends/xnnpack/runtime/XNNWeightsCache.cpp b/backends/xnnpack/runtime/XNNWeightsCache.cpp index 54191b72825..303076460ed 100644 --- a/backends/xnnpack/runtime/XNNWeightsCache.cpp +++ b/backends/xnnpack/runtime/XNNWeightsCache.cpp @@ -208,6 +208,12 @@ size_t XNNWeightsCache::look_up_or_insert( if (offset != SIZE_MAX) { void* saved_ptr = context->offset_to_addr(context, offset); + // Check for null pointers before calling memcmp + if (ptr == nullptr || saved_ptr == nullptr) { + // If either pointer is null (due to deleted data or allocation failure), treat as cache miss + // and return SIZE_MAX to trigger reinsertion. + return SIZE_MAX; + } if (0 == memcmp(ptr, saved_ptr, size)) { return offset; }