[icinga-checkins] icinga.org: icinga-core/gbeutner/ido: Fix initial cache fill: empty name2 was incorrectly converted to "(null)".

git at icinga.org git at icinga.org
Tue Apr 30 11:55:19 CEST 2013


Module: icinga-core
Branch: gbeutner/ido
Commit: 8dc2cb003409d6ea23c700b1d7bebe41d1433656
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=8dc2cb003409d6ea23c700b1d7bebe41d1433656

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Apr 30 11:54:41 2013 +0200

Fix initial cache fill: empty name2 was incorrectly converted to "(null)".

---

 module/idoutils/src/dbhandlers.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/module/idoutils/src/dbhandlers.c b/module/idoutils/src/dbhandlers.c
index eff8178..3f6ac0e 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -500,13 +500,16 @@ int ido2db_get_cached_object_ids(ido2db_idi *idi) {
 
 			while (idi->dbinfo.dbi_result) {
 				if (dbi_result_next_row(idi->dbinfo.dbi_result)) {
+					char *name2;
+					
 					object_id = dbi_result_get_ulonglong(idi->dbinfo.dbi_result, "object_id");
 					objecttype_id = dbi_result_get_ulonglong(idi->dbinfo.dbi_result, "objecttype_id");
 
 					/* get string and free it later on */
 					if (asprintf(&tmp1, "%s", dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name1")) == -1)
 						tmp1 = NULL;
-					if (asprintf(&tmp2, "%s", dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name2")) == -1)
+					name2 = dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name2");
+					if (!name2 || asprintf(&tmp2, "%s", name2) == -1)
 						tmp2 = NULL;
 
 					ido2db_add_cached_object_id(idi, objecttype_id, tmp1, tmp2, object_id);
@@ -557,6 +560,7 @@ int ido2db_get_cached_object_ids(ido2db_idi *idi) {
 	idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_select_cached);
 
 	if (OCI_FetchNext(idi->dbinfo.oci_resultset)) {
+		char *name2;
 
 		ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_ids() fetchnext ok\n");
 		object_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("id"));
@@ -565,7 +569,8 @@ int ido2db_get_cached_object_ids(ido2db_idi *idi) {
 		/* dirty little hack for mtext* <-> char* */
 		if (asprintf(&tmp1, "%s", OCI_GetString2(idi->dbinfo.oci_resultset, MT("name1"))) == -1)
 			tmp1 = NULL;
-		if (asprintf(&tmp2, "%s", OCI_GetString2(idi->dbinfo.oci_resultset, MT("name2"))) == -1)
+		name2 = OCI_GetString2(idi->dbinfo.oci_resultset, MT("name2"));
+		if (!name2 || asprintf(&tmp2, "%s", name2) == -1)
 			tmp2 = NULL;
 
 		ido2db_add_cached_object_id(idi, objecttype_id, tmp1, tmp2, object_id);





More information about the icinga-checkins mailing list