Skip to content

Commit

Permalink
fix(gui): add missing sync in clean task at search dialog close (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Dec 21, 2024
1 parent fe0ab5e commit 73966fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
16 changes: 9 additions & 7 deletions jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,15 @@ public void unload() {
if (state == NOT_LOADED) {
return;
}
methods.forEach(MethodNode::unload);
innerClasses.forEach(ClassNode::unload);
fields.forEach(FieldNode::unload);
unloadAttributes();
setState(NOT_LOADED);
this.loadStage = LoadStage.NONE;
this.smali = null;
synchronized (clsInfo) { // decompilation sync
methods.forEach(MethodNode::unload);
innerClasses.forEach(ClassNode::unload);
fields.forEach(FieldNode::unload);
unloadAttributes();
setState(NOT_LOADED);
this.loadStage = LoadStage.NONE;
this.smali = null;
}
}

private void buildCache() {
Expand Down
10 changes: 10 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/jobs/BackgroundExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.LoggerFactory;

import jadx.api.utils.tasks.ITaskExecutor;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.gui.settings.JadxSettings;
import jadx.gui.ui.MainWindow;
import jadx.gui.ui.panel.ProgressPanel;
Expand Down Expand Up @@ -81,6 +82,15 @@ public synchronized void cancelAll() {
}
}

public synchronized void waitForComplete() {
try {
// add empty task and wait its completion
taskQueueExecutor.submit(UiUtils.EMPTY_RUNNABLE).get();
} catch (Exception e) {
throw new JadxRuntimeException("Failed to wait tasks completion", e);
}
}

public void execute(String title, List<Runnable> backgroundJobs, Consumer<TaskStatus> onFinishUiRunnable) {
execute(new SimpleTask(title, backgroundJobs, onFinishUiRunnable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public void dispose() {
removeActiveTabListener();
searchBackgroundExecutor.execute(() -> {
stopSearchTask();
mainWindow.getBackgroundExecutor().waitForComplete();
unloadTempData();
});
super.dispose();
Expand Down

0 comments on commit 73966fd

Please sign in to comment.