Fix some memory leaks.

Fixes #3224
Closes #3228
// FREEBIE
This commit is contained in:
Moxie Marlinspike
2015-06-12 13:54:47 -07:00
parent e420861151
commit ed0e1c07b9
3 changed files with 18 additions and 22 deletions

View File

@@ -23,9 +23,11 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.SmsMigrator;
import org.thoughtcrime.securesms.database.SmsMigrator.ProgressDescription;
import java.lang.ref.WeakReference;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
// FIXME: This class is nuts.
public class ApplicationMigrationService extends Service
implements SmsMigrator.SmsMigrationProgressListener
{
@@ -39,9 +41,9 @@ public class ApplicationMigrationService extends Service
private final Binder binder = new ApplicationMigrationBinder();
private final Executor executor = Executors.newSingleThreadExecutor();
private Handler handler = null;
private WeakReference<Handler> handler = null;
private NotificationCompat.Builder notification = null;
private ImportState state = new ImportState(ImportState.STATE_IDLE, null);
private ImportState state = new ImportState(ImportState.STATE_IDLE, null);
@Override
public void onCreate() {
@@ -70,7 +72,7 @@ public class ApplicationMigrationService extends Service
}
public void setImportStateHandler(Handler handler) {
this.handler = handler;
this.handler = new WeakReference<>(handler);
}
private void registerCompletedReceiver() {
@@ -103,6 +105,8 @@ public class ApplicationMigrationService extends Service
private void setState(ImportState state) {
this.state = state;
Handler handler = this.handler.get();
if (handler != null) {
handler.obtainMessage(state.state, state.progress).sendToTarget();
}

View File

@@ -21,7 +21,6 @@ import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.util.DirectoryHelper;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
@@ -34,6 +33,7 @@ import org.whispersystems.textsecure.api.TextSecureAccountManager;
import org.whispersystems.textsecure.api.push.exceptions.ExpectationFailedException;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -77,7 +77,7 @@ public class RegistrationService extends Service {
private volatile RegistrationState registrationState = new RegistrationState(RegistrationState.STATE_IDLE);
private volatile Handler registrationStateHandler;
private volatile WeakReference<Handler> registrationStateHandler;
private volatile ChallengeReceiver challengeReceiver;
private String challenge;
private long verificationStartTime;
@@ -298,6 +298,8 @@ public class RegistrationService extends Service {
private void setState(RegistrationState state) {
this.registrationState = state;
Handler registrationStateHandler = this.registrationStateHandler.get();
if (registrationStateHandler != null) {
registrationStateHandler.obtainMessage(state.state, state).sendToTarget();
}
@@ -319,7 +321,7 @@ public class RegistrationService extends Service {
}
public void setRegistrationStateHandler(Handler registrationStateHandler) {
this.registrationStateHandler = registrationStateHandler;
this.registrationStateHandler = new WeakReference<>(registrationStateHandler);
}
public class RegistrationServiceBinder extends Binder {