diff --git a/include/fmt/format.h b/include/fmt/format.h
index 1db4528d..52daed7d 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -775,6 +775,7 @@ class basic_memory_buffer final : public detail::buffer<T> {
       // Set pointer to the inline array so that delete is not called
       // when deallocating.
       other.set(other.store_, 0);
+      other.clear();
     }
     this->resize(size);
   }
@@ -2896,7 +2897,7 @@ template <typename Enum, FMT_ENABLE_IF(std::is_enum<Enum>::value)>
 constexpr auto format_as(Enum e) noexcept -> underlying_t<Enum> {
   return static_cast<underlying_t<Enum>>(e);
 }
-}
+}  // namespace enums
 
 #ifdef __cpp_lib_byte
 inline auto format_as(std::byte b) -> unsigned char { return underlying(b); }
diff --git a/test/format-test.cc b/test/format-test.cc
index 35aee406..96b5f1ae 100644
--- a/test/format-test.cc
+++ b/test/format-test.cc
@@ -250,8 +250,9 @@ TEST(memory_buffer_test, move_ctor_dynamic_buffer) {
   buffer.push_back('a');
   basic_memory_buffer<char, 4, std_allocator> buffer2(std::move(buffer));
   // Move should rip the guts of the first buffer.
-  EXPECT_EQ(inline_buffer_ptr, &buffer[0]);
-  EXPECT_EQ("testa", std::string(&buffer2[0], buffer2.size()));
+  EXPECT_EQ(&buffer[0], inline_buffer_ptr);
+  EXPECT_EQ(buffer.size(), 0);
+  EXPECT_EQ(std::string(&buffer2[0], buffer2.size()), "testa");
   EXPECT_GT(buffer2.capacity(), 4u);
 }