r13360: Fix crash bug when 0 results are returned on the internal base search
[tprouty/samba.git] / source4 / lib / ldb / modules / asq.c
index 7e6bbdf29ea899e17f62f6f7c9dec7cc1cfa84b0..905bab480a363cb00c3d26f3ea6bc9df7076a4f0 100644 (file)
@@ -126,14 +126,22 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req)
 
        ret = ldb_request(module->ldb, base_req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(base_req);
                return ret;
+       }
 
+       if (base_req->op.search.res->count == 0) {
+               talloc_free(base_req);
+               return build_response(res, ASQ_CTRL_SUCCESS);
+       }
+       
        /* look up the DNs */
        el = ldb_msg_find_element(base_req->op.search.res->msgs[0],
                                  asq_ctrl->source_attribute);
        /* no values found */
        if (el == NULL) {
+               talloc_free(base_req);
                return build_response(res, ASQ_CTRL_SUCCESS);
        }
 
@@ -181,6 +189,8 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req)
                talloc_free(exp_req);
        }
 
+       talloc_free(base_req);
+
        return build_response(res, ASQ_CTRL_SUCCESS);
 }