提交 a0876eb7 编写于 作者: Z zyyang

[TD-1883]<fix>: fix memory leak when resultSet pointer is null

上级 f3420428
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.6</version> <version>2.0.9</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>JDBCDriver</name> <name>JDBCDriver</name>
......
...@@ -111,8 +111,8 @@ public class TSDBJNIConnector { ...@@ -111,8 +111,8 @@ public class TSDBJNIConnector {
* @throws SQLException * @throws SQLException
*/ */
public long executeQuery(String sql) throws SQLException { public long executeQuery(String sql) throws SQLException {
// close previous result set if the user forgets to invoke the // close previous result set if the user forgets to invoke the
// free method to close previous result set. // free method to close previous result set.
if (!this.isResultsetClosed) { if (!this.isResultsetClosed) {
freeResultSet(taosResultSetPointer); freeResultSet(taosResultSetPointer);
} }
...@@ -122,23 +122,23 @@ public class TSDBJNIConnector { ...@@ -122,23 +122,23 @@ public class TSDBJNIConnector {
pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
this.freeResultSet(pSql); this.freeResultSetImp(this.taos, pSql);
throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding")); throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding"));
} }
int code = this.getErrCode(pSql); int code = this.getErrCode(pSql);
if (code != 0) { if (code != 0) {
affectedRows = -1; affectedRows = -1;
String msg = this.getErrMsg(pSql); String msg = this.getErrMsg(pSql);
this.freeResultSet(pSql); this.freeResultSetImp(this.taos, pSql);
throw new SQLException(TSDBConstants.WrapErrMsg(msg), "", code); throw new SQLException(TSDBConstants.WrapErrMsg(msg), "", code);
} }
// Try retrieving result set for the executed SQL using the current connection pointer. // Try retrieving result set for the executed SQL using the current connection pointer.
taosResultSetPointer = this.getResultSetImp(this.taos, pSql); taosResultSetPointer = this.getResultSetImp(this.taos, pSql);
isResultsetClosed = (taosResultSetPointer == TSDBConstants.JNI_NULL_POINTER); isResultsetClosed = (taosResultSetPointer == TSDBConstants.JNI_NULL_POINTER);
return pSql; return pSql;
} }
...@@ -171,11 +171,11 @@ public class TSDBJNIConnector { ...@@ -171,11 +171,11 @@ public class TSDBJNIConnector {
} }
private native long getResultSetImp(long connection, long pSql); private native long getResultSetImp(long connection, long pSql);
public boolean isUpdateQuery(long pSql) { public boolean isUpdateQuery(long pSql) {
return isUpdateQueryImp(this.taos, pSql) == 1? true:false; return isUpdateQueryImp(this.taos, pSql) == 1 ? true : false;
} }
private native long isUpdateQueryImp(long connection, long pSql); private native long isUpdateQueryImp(long connection, long pSql);
/** /**
...@@ -191,7 +191,7 @@ public class TSDBJNIConnector { ...@@ -191,7 +191,7 @@ public class TSDBJNIConnector {
res = this.freeResultSetImp(this.taos, result); res = this.freeResultSetImp(this.taos, result);
taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
} }
isResultsetClosed = true; isResultsetClosed = true;
return res; return res;
} }
...@@ -274,7 +274,7 @@ public class TSDBJNIConnector { ...@@ -274,7 +274,7 @@ public class TSDBJNIConnector {
* Consume a subscription * Consume a subscription
*/ */
long consume(long subscription) { long consume(long subscription) {
return this.consumeImp(subscription); return this.consumeImp(subscription);
} }
private native long consumeImp(long subscription); private native long consumeImp(long subscription);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册