Skip to content

Commit 423c1fd

Browse files
authored
Merge pull request #386 from NigelWu95/dev5
fix memory leak problem because of some unclosed okhttp response.
2 parents c7e8a27 + 79eb019 commit 423c1fd

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/main/java/com/qiniu/storage/BucketManager.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ public FileListing listFiles(String bucket, String prefix, String marker, int li
190190
* @link http://developer.qiniu.com/kodo/api/stat
191191
*/
192192
public FileInfo stat(String bucket, String fileKey) throws QiniuException {
193-
Response r = rsGet(bucket, String.format("/stat/%s", encodedEntry(bucket, fileKey)));
194-
return r.jsonToObject(FileInfo.class);
193+
Response res = rsGet(bucket, String.format("/stat/%s", encodedEntry(bucket, fileKey)));
194+
if (!res.isOK()) {
195+
throw new QiniuException(res);
196+
}
197+
FileInfo fileInfo = res.jsonToObject(FileInfo.class);
198+
res.close();
199+
return fileInfo;
195200
}
196201

197202
/**
@@ -330,7 +335,11 @@ public Response copy(String fromBucket, String fromFileKey, String toBucket, Str
330335
*/
331336
public void copy(String fromBucket, String fromFileKey, String toBucket, String toFileKey)
332337
throws QiniuException {
333-
copy(fromBucket, fromFileKey, toBucket, toFileKey, false);
338+
Response res = copy(fromBucket, fromFileKey, toBucket, toFileKey, false);
339+
if (!res.isOK()) {
340+
throw new QiniuException(res);
341+
}
342+
res.close();
334343
}
335344

336345
/**
@@ -391,8 +400,13 @@ public FetchRet fetch(String url, String bucket, String key) throws QiniuExcepti
391400
String resource = UrlSafeBase64.encodeToString(url);
392401
String to = encodedEntry(bucket, key);
393402
String path = String.format("/fetch/%s/to/%s", resource, to);
394-
Response r = ioPost(bucket, path);
395-
return r.jsonToObject(FetchRet.class);
403+
Response res = ioPost(bucket, path);
404+
if (!res.isOK()) {
405+
throw new QiniuException(res);
406+
}
407+
FetchRet fetchRet = res.jsonToObject(FetchRet.class);
408+
res.close();
409+
return fetchRet;
396410
}
397411

398412
/**
@@ -470,7 +484,11 @@ public Response checkAsynFetchid(String region, String fetchWorkId) throws Qiniu
470484
public void prefetch(String bucket, String key) throws QiniuException {
471485
String resource = encodedEntry(bucket, key);
472486
String path = String.format("/prefetch/%s", resource);
473-
ioPost(bucket, path);
487+
Response res = ioPost(bucket, path);
488+
if (!res.isOK()) {
489+
throw new QiniuException(res);
490+
}
491+
res.close();
474492
}
475493

476494
/**
@@ -527,27 +545,31 @@ public Response deleteAfterDays(String bucket, String key, int days) throws Qini
527545
public void setBucketAcl(String bucket, AclType acl) throws QiniuException {
528546
String url = String.format("%s/private?bucket=%s&private=%s", configuration.ucHost(), bucket, acl.getType());
529547
Response res = post(url, null);
530-
res.close();
531548
if (!res.isOK()) {
532549
throw new QiniuException(res);
533550
}
551+
res.close();
534552
}
535553

536554
public BucketInfo getBucketInfo(String bucket) throws QiniuException {
537555
String url = String.format("%s/v2/bucketInfo?bucket=%s", configuration.ucHost(), bucket);
538556
Response res = post(url, null);
539557
if (!res.isOK()) {
540-
res.close();
541558
throw new QiniuException(res);
542559
}
543560
BucketInfo info = res.jsonToObject(BucketInfo.class);
561+
res.close();
544562
return info;
545563
}
546564

547565
public void setIndexPage(String bucket, IndexPageType type) throws QiniuException {
548566
String url = String.format("%s/noIndexPage?bucket=%s&noIndexPage=%s",
549567
configuration.ucHost(), bucket, type.getType());
550568
Response res = post(url, null);
569+
if (!res.isOK()) {
570+
throw new QiniuException(res);
571+
}
572+
res.close();
551573
}
552574

553575
/*

0 commit comments

Comments
 (0)