Skip to content

Commit

Permalink
fix: fix resource leaks in 3 classes (#4449)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk2k committed Jul 6, 2024
1 parent 123316b commit a164bca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
if (params != null && params.containsKey("ledger_id")) {
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
BookKeeper bk = new BookKeeper(clientConf);
Long ledgerId = Long.parseLong(params.get("ledger_id"));
try (BookKeeper bk = new BookKeeper(clientConf)) {
Long ledgerId = Long.parseLong(params.get("ledger_id"));

bk.deleteLedger(ledgerId);
bk.deleteLedger(ledgerId);

String output = "Deleted ledger: " + ledgerId;
String jsonResponse = JsonUtil.toJson(output);
if (LOG.isDebugEnabled()) {
LOG.debug("output body:" + jsonResponse);
String output = "Deleted ledger: " + ledgerId;
String jsonResponse = JsonUtil.toJson(output);
if (LOG.isDebugEnabled()) {
LOG.debug("output body:" + jsonResponse);
}
response.setBody(jsonResponse);
response.setCode(HttpServer.StatusCode.OK);
return response;
}
response.setBody(jsonResponse);
response.setCode(HttpServer.StatusCode.OK);
return response;
} else {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Not ledger found. Should provide ledger_id=<id>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ public void deleteLog(String logName)
if (!uri.isPresent()) {
throw new LogNotFoundException("Log " + logName + " isn't found.");
}
DistributedLogManager dlm = openLogInternal(
try (DistributedLogManager dlm = openLogInternal(
uri.get(),
logName,
Optional.empty(),
Optional.empty());
dlm.delete();
Optional.empty())) {
dlm.delete();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ public Map<String, byte[]> enumerateLogsWithMetadataInNamespace()
String namespaceRootPath = namespace.getPath();
HashMap<String, byte[]> result = new HashMap<String, byte[]>();
ZooKeeperClient zkc = writerZKC;
try {
ZooKeeper zk = Utils.sync(zkc, namespaceRootPath);
try (ZooKeeper zk = Utils.sync(zkc, namespaceRootPath)) {
Stat currentStat = zk.exists(namespaceRootPath, false);
if (currentStat == null) {
return result;
Expand Down

0 comments on commit a164bca

Please sign in to comment.