Skip to content

Commit 4d7f510

Browse files
committed
{178645691}: Fixing invalid memory in reqlog
The long-running-query logging looks at `clnt->sql`, and may race with the cleanup of verify-replay history, which releases the buffer that `clnt->sql` points into. This patch fixes it. Signed-off-by: Rivers Zhang <[email protected]>
1 parent a46ebb6 commit 4d7f510

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

db/osql_srs.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ int srs_tran_del_last_query(struct sqlclntstate *clnt)
177177
return 0;
178178
}
179179

180+
static inline int srs_tran_do_not_retry(struct sqlclntstate *clnt)
181+
{
182+
return (clnt->verifyretry_off || clnt->isselect || clnt->dbtran.trans_has_sp || clnt->has_recording);
183+
}
184+
180185
/**
181186
* Add a new query to the transaction
182187
*
@@ -186,10 +191,8 @@ int srs_tran_add_query(struct sqlclntstate *clnt)
186191
osqlstate_t *osql = &clnt->osql;
187192
srs_tran_query_t *item = NULL;
188193

189-
if (clnt->verifyretry_off || clnt->isselect || clnt->dbtran.trans_has_sp ||
190-
clnt->has_recording) {
194+
if (srs_tran_do_not_retry(clnt))
191195
return 0;
192-
}
193196

194197
/* don't grow session when the transaction is simply repeated */
195198
if (osql->replay != OSQL_RETRY_NONE) {
@@ -232,6 +235,14 @@ int srs_tran_empty(struct sqlclntstate *clnt)
232235
osqlstate_t *osql = &clnt->osql;
233236
srs_tran_query_t *item = NULL, *tmp = NULL;
234237

238+
if (!srs_tran_do_not_retry(clnt)) {
239+
Pthread_mutex_lock(&clnt->sql_lk);
240+
/* clnt->sql points into a buffer in clnt->appdata->query.
241+
* ensure that it's set to NULL before we free the memory */
242+
clnt->sql = NULL;
243+
Pthread_mutex_unlock(&clnt->sql_lk);
244+
}
245+
235246
LISTC_FOR_EACH_SAFE(&osql->history->lst, item, tmp, lnk)
236247
{
237248
listc_rfl(&osql->history->lst, item);

0 commit comments

Comments
 (0)