Skip to content

Commit

Permalink
Do not leak client instance to DownloadWithUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Feb 27, 2019
1 parent 6c7f5f4 commit f92b9f9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final <R> void send(@NonNull final AriaRequestWithResult<R> request, fina
send(request.id, obj, new OnJson() {
@Override
public void onResponse(@NonNull JSONObject response) throws JSONException {
R result = request.processor.process(AbstractClient.this, response);
R result = request.processor.process(NetInstanceHolder.referenceFor(AbstractClient.this), response);
handler.post(() -> listener.onResult(result));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void getVersionAndSession(AbstractClient.OnResult<VersionAndSession> list
client.batch(VERSION_AND_SESSION_BATCH_SANDBOX, listener);
}

public void tellAllAndGlobalStats(final AbstractClient.OnResult<DownloadsAndGlobalStats> listener) {
public void tellAllAndGlobalStats(AbstractClient.OnResult<DownloadsAndGlobalStats> listener) {
client.batch(DOWNLOADS_AND_GLOBAL_STATS_BATCH_SANDBOX, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ static void hasBeenClosed(@NonNull AbstractClient client) {
instance.current = null;
}

@NonNull
public static ClientInterface referenceFor(AbstractClient client) {
if (instance.current == client) return instance.reference;
else return client;
}

private void handleInstantiate(@NonNull MultiProfile.UserProfile profile) throws AbstractClient.InitializationException {
if (profile.connectionMethod == MultiProfile.ConnectionMethod.WEBSOCKET) {
if (!(current instanceof WebSocketClient)) {
Expand Down

0 comments on commit f92b9f9

Please sign in to comment.