only: fix potential IOStream leak: Method `DfuHelper.sendDfuRebootCommand` shouldn't be responsible for closing a stream, because there are cases, when overloaded `DfuHelper.sendDfuRebootCommand` method doesn't call its namesake (that was closing the stream)
This commit is contained in:
parent
c7fefcef25
commit
07fe982aa5
|
@ -5,7 +5,6 @@ import com.rusefi.core.RusEfiSignature;
|
|||
import com.rusefi.core.SignatureHelper;
|
||||
import com.rusefi.core.io.BundleUtil;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.ui.StatusConsumer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
|
@ -18,11 +17,10 @@ public class DfuHelper {
|
|||
private static final Logging log = getLogging(DfuHelper.class);
|
||||
private static final String PREFIX = "rusefi_bundle";
|
||||
|
||||
public static void sendDfuRebootCommand(IoStream stream, UpdateOperationCallbacks callbacks, String cmd) {
|
||||
private static void sendDfuRebootCommand(IoStream stream, UpdateOperationCallbacks callbacks, String cmd) {
|
||||
byte[] command = BinaryProtocol.getTextCommandBytes(cmd);
|
||||
try {
|
||||
stream.sendPacket(command);
|
||||
stream.close();
|
||||
callbacks.logLine(String.format("Reboot command [%s] sent into %s!\n", cmd, stream));
|
||||
} catch (IOException e) {
|
||||
callbacks.logLine("Error " + e);
|
||||
|
|
|
@ -75,27 +75,28 @@ public class DfuFlasher {
|
|||
AtomicBoolean isSignatureValidated = new AtomicBoolean(true);
|
||||
if (!PortDetector.isAutoPort(port)) {
|
||||
callbacks.logLine("Using selected " + port + "\n");
|
||||
IoStream stream = BufferedSerialIoStream.openPort(port);
|
||||
AtomicReference<String> signature = new AtomicReference<>();
|
||||
SerialAutoChecker.checkResponse(stream, callbackContext -> {
|
||||
signature.set(callbackContext.getSignature());
|
||||
return null;
|
||||
});
|
||||
if (signature.get() == null) {
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("Make sure TUNERSTUDIO IS DISCONNECTED FROM ECU");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("*** ERROR *** rusEFI has not responded on selected " + port + "\n" +
|
||||
try (final IoStream stream = BufferedSerialIoStream.openPort(port)) {
|
||||
AtomicReference<String> signature = new AtomicReference<>();
|
||||
SerialAutoChecker.checkResponse(stream, callbackContext -> {
|
||||
signature.set(callbackContext.getSignature());
|
||||
return null;
|
||||
});
|
||||
if (signature.get() == null) {
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("Make sure TUNERSTUDIO IS DISCONNECTED FROM ECU");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("");
|
||||
callbacks.appendLine("*** ERROR *** rusEFI has not responded on selected " + port + "\n" +
|
||||
"Maybe try automatic serial port detection?");
|
||||
callbacks.error();
|
||||
return null;
|
||||
callbacks.error();
|
||||
return null;
|
||||
}
|
||||
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, signature.get(), stream, callbacks, command);
|
||||
isSignatureValidated.set(isSignatureValidatedLocal);
|
||||
}
|
||||
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, signature.get(), stream, callbacks, command);
|
||||
isSignatureValidated.set(isSignatureValidatedLocal);
|
||||
} else {
|
||||
callbacks.logLine("Auto-detecting port...\n");
|
||||
// instead of opening the just-detected port we execute the command using the same stream we used to discover port
|
||||
|
|
Loading…
Reference in New Issue