Memory Leak in public InputStream readResource(Object resourceId)
-----------------------------------------------------------------
Key: TRANSACTION-40
URL: https://issues.apache.org/jira/browse/TRANSACTION-40
Project: Commons Transaction
Issue Type: Bug
Affects Versions: 1.2
Environment: Any
Reporter: Anej Bansal
Fix For: 1.2
It appears that the following method has a memory leak,
public InputStream readResource(Object resourceId);
The 1.2 release implementation, create a temporary light weight tx for reading,
the tx is added to the globalTransactions, however, it is NEVER removed from
the globalTransactions map. The public boolean resourceExists(Object
resourceId) is implemented in a similar fashion, however, temporary tx is
removed on completion.
Current Code:
public InputStream readResource(Object resourceId)
throws ResourceManagerException
{
Object txId;
synchronized (this.globalTransactions) {
txId = generatedUniqueTxId();
if (this.logger.isFinerEnabled())
this.logger.logFiner("Creating temporary light weight tx " + txId + "
for reading");
TransactionContext context = new TransactionContext(txId);
context.isLightWeight = true;
context.isolationLevel = 10;
this.globalTransactions.put(txId, context);
}
InputStream is = readResource(txId, resourceId);
return is;
}
Fixed Code
public InputStream readResource(Object resourceId)
throws ResourceManagerException
{
Object txId;
synchronized (this.globalTransactions) {
txId = generatedUniqueTxId();
if (this.logger.isFinerEnabled())
this.logger.logFiner("Creating temporary light weight tx " + txId + "
for reading");
TransactionContext context = new TransactionContext(txId);
context.isLightWeight = true;
context.isolationLevel = 10;
this.globalTransactions.put(txId, context);
}
InputStream is = readResource(txId, resourceId);
context.freeLocks();
this.globalTransactions.remove(txId);
if (this.logger.isFinerEnabled()) {
this.logger.logFiner("Removing temporary light weight tx " + txId);
}
return is;
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.