Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3223_emteere code review changes

emteere136c41c027ac
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/mem/MemoryManagerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/mem/MemoryManagerTest.java
index d1aa6e5732..9d04c3b0c4 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/mem/MemoryManagerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/mem/MemoryManagerTest.java
@@ -366,8 +366,13 @@ public class MemoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
block = mem.getBlock("NoExist");
assertNull(block);
+ program.endTransaction(transactionID, true);
+ transactionID = program.startTransaction("Test");
+
// now exists
mem.getBlock("Test1").setName("NoExist");
+ // Test1 no longer exists
+ assertNull("block deleted", mem.getBlock("Test1"));
block = mem.getBlock("NoExist");
assertEquals("NoExist", block.getName());
@@ -375,11 +380,22 @@ public class MemoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
block = mem.getBlock("NoExist");
assertNull("block should be deleted", block);
+ // Test1 still doesn't exist
block = mem.getBlock("Test1");
assertNull("block deleted", block);
block = mem.getBlock("Test2");
assertEquals("Test2", block.getName());
+
+ program.endTransaction(transactionID, true);
+
+ program.undo();
+
+ // Test1 still doesn't exist
+ block = mem.getBlock("Test1");
+ assertNotNull("Undo, Test1 exists again", block);
+
+ transactionID = program.startTransaction("Test");
}
@Test
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
index 5769d32d01..21edabe4a6 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
@@ -309,9 +309,12 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
public synchronized MemoryBlock getBlock(String blockName) {
// find block that might have been cached from previous call
MemoryBlock memoryBlock = nameBlockMap.get(blockName);
- if (memoryBlock == NoBlock) {
- // found placeholder, have searched and found nothing before
- return null;
+ if (memoryBlock != null) {
+ if (memoryBlock == NoBlock) {
+ // found placeholder, have searched and found nothing before
+ return null;
+ }
+ return memoryBlock;
}
for (MemoryBlock block : blocks) {