Ghidra is a software reverse engineering (SRE) framework
GP-5121: Fix unflushed buffer in Saveable TracePropertyMap
Dan2f86a780f056
diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/map/AbstractDBTracePropertyMap.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/map/AbstractDBTracePropertyMap.javaindex b6cf7ba17b..cc3597a971 100644--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/map/AbstractDBTracePropertyMap.java+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/map/AbstractDBTracePropertyMap.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -28,7 +28,6 @@ import ghidra.program.model.address.*;import ghidra.program.model.lang.Language;import ghidra.trace.database.DBTrace;import ghidra.trace.database.DBTraceUtils;-import ghidra.trace.database.map.AbstractDBTracePropertyMap.DBTraceSaveablePropertyMapEntry;import ghidra.trace.database.map.DBTraceAddressSnapRangePropertyMapTree.AbstractDBTraceAddressSnapRangePropertyMapData;import ghidra.trace.database.map.DBTraceAddressSnapRangePropertyMapTree.TraceAddressSnapRangeQuery;import ghidra.trace.database.thread.DBTraceThreadManager;@@ -399,16 +398,16 @@ public abstract class AbstractDBTracePropertyMap<T, DR extends AbstractDBTraceAdif (value == null) {return null;}- try {- ByteArrayOutputStream os = new ByteArrayOutputStream();- ObjectStorage objStorage =- new ObjectStorageStreamAdapter(new ObjectOutputStream(os));++ ByteArrayOutputStream os = new ByteArrayOutputStream();+ try (ObjectOutputStream objStream = new ObjectOutputStream(os)) {+ ObjectStorage objStorage = new ObjectStorageStreamAdapter(objStream);value.save(objStorage);- return os.toByteArray();}catch (IOException e) {throw new AssertionError(e); // For a ByteArrayOutputStream?}+ return os.toByteArray();}@Overridediff --git a/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/trace/database/property/DBTraceAddressPropertyManagerTest.java b/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/trace/database/property/DBTraceAddressPropertyManagerTest.javaindex 8f8d5dc1ad..fd20ed50a0 100644--- a/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/trace/database/property/DBTraceAddressPropertyManagerTest.java+++ b/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/trace/database/property/DBTraceAddressPropertyManagerTest.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -50,13 +50,9 @@ public class DBTraceAddressPropertyManagerTest extends AbstractGhidraHeadlessInt@Overridepublic boolean equals(Object obj) {- if (obj == this) {- return true;- }- if (!(obj instanceof MySaveable)) {+ if (!(obj instanceof MySaveable that)) {return false;}- MySaveable that = (MySaveable) obj;return this.i == that.i && Objects.equals(this.str, that.str);}@@ -117,13 +113,9 @@ public class DBTraceAddressPropertyManagerTest extends AbstractGhidraHeadlessInt@Overridepublic boolean equals(Object obj) {- if (obj == this) {- return true;- }- if (!(obj instanceof ExtMySaveable)) {+ if (!(obj instanceof ExtMySaveable that)) {return false;}- ExtMySaveable that = (ExtMySaveable) obj;return super.equals(that) && this.f == that.f;}@@ -335,7 +327,12 @@ public class DBTraceAddressPropertyManagerTest extends AbstractGhidraHeadlessInt}@Test- public void testStringMapAtNoAdress() throws Exception {+ public void testExtSaveableMap() throws Exception {+ doTestMap(ExtMySaveable.class, new ExtMySaveable(6, "MyString", 0.5f));+ }++ @Test+ public void testStringMapAtNoAddress() throws Exception {TracePropertyMap<String> map;try (Transaction tx = tb.startTransaction()) {map = propertyManager.createPropertyMap("MyProp", String.class);