Module: sip-router Branch: master Commit: f27df26ca01394250cbe12c5ccf694c6afd3707f URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f27df26c...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue Mar 4 09:59:07 2014 +0100
sqlops: safety check for result row field
- it might not be set in case of a failure in the middle of result conversion from db to internal memory - freeing the partial result could result in a crash - reported by Juha Heinanen
---
modules/sqlops/sql_api.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/modules/sqlops/sql_api.c b/modules/sqlops/sql_api.c index 6528078..bfd4e96 100644 --- a/modules/sqlops/sql_api.c +++ b/modules/sqlops/sql_api.c @@ -228,13 +228,16 @@ void sql_reset_result(sql_result_t *res) { for(i=0; i<res->nrows; i++) { - for(j=0; j<res->ncols; j++) + if(res->vals[i]) { - if(res->vals[i][j].flags&PV_VAL_STR - && res->vals[i][j].value.s.len>0) - pkg_free(res->vals[i][j].value.s.s); + for(j=0; j<res->ncols; j++) + { + if(res->vals[i][j].flags&PV_VAL_STR + && res->vals[i][j].value.s.len>0) + pkg_free(res->vals[i][j].value.s.s); + } + pkg_free(res->vals[i]); } - pkg_free(res->vals[i]); } pkg_free(res->vals); res->vals = NULL;