From af4cdf4b91387ec5884df661541017104ea01f4a Mon Sep 17 00:00:00 2001 From: Anton Batenev Date: Fri, 21 Oct 2011 17:30:09 +0400 Subject: [PATCH] * Fix nginx crash on signal 11 when gridfs_find_query returns MONGO_ERROR (gfile variable is not initialized); * Fix mongo_cursor memleak in ngx_http_mongo_authenticate; * Also there is memleak in ngx_http_mongo_add_connection <- mongo_connect <- bson_malloc, but it is not critical. --- ngx_http_gridfs_module.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ngx_http_gridfs_module.c b/ngx_http_gridfs_module.c index cd2181b..bdf5bbf 100644 --- a/ngx_http_gridfs_module.c +++ b/ngx_http_gridfs_module.c @@ -418,6 +418,7 @@ ngx_http_mongo_connection_t* ngx_http_get_mongo_connection( ngx_str_t name ) { static ngx_int_t ngx_http_mongo_authenticate(ngx_log_t *log, ngx_http_gridfs_loc_conf_t *gridfs_loc_conf) { ngx_http_mongo_connection_t* mongo_conn; ngx_http_mongo_auth_t *mongo_auth; + mongo_cursor *cursor = NULL; bson empty; char *test; int error; @@ -452,9 +453,10 @@ static ngx_int_t ngx_http_mongo_authenticate(ngx_log_t *log, ngx_http_gridfs_loc ngx_cpystrn((u_char*)test, (u_char*)gridfs_loc_conf->db.data, gridfs_loc_conf->db.len+1); ngx_cpystrn((u_char*)(test+gridfs_loc_conf->db.len),(u_char*)".test", sizeof(".test")); bson_empty(&empty); - mongo_find(&mongo_conn->conn, test, &empty, NULL, 0, 0, 0); + cursor = mongo_find(&mongo_conn->conn, test, &empty, NULL, 0, 0, 0); error = mongo_cmd_get_last_error(&mongo_conn->conn, (char*)gridfs_loc_conf->db.data, NULL); free(test); + mongo_cursor_destroy(cursor); if (error) { ngx_log_error(NGX_LOG_ERR, log, 0, "Authentication Required"); return NGX_ERROR; @@ -786,7 +788,6 @@ static ngx_int_t ngx_http_gridfs_handler(ngx_http_request_t* request) { free(value); if(status == MONGO_ERROR) { - gridfile_destroy(&gfile); gridfs_destroy(&gfs); return NGX_HTTP_NOT_FOUND; }