diff mbox

[opensm] osm_db_files.c: Some minor fixes/improvements to osm_db_store

Message ID 52C1987A.6000802@dev.mellanox.co.il (mailing list archive)
State Accepted
Delegated to: Hal Rosenstock
Headers show

Commit Message

Hal Rosenstock Dec. 30, 2013, 3:59 p.m. UTC
1. Check p_domain_imp->dirty flag under lock
2. Handle malloc failure for temporary file name
3. Move malloc outside of lock

Items 1 and 2 above were:
Pointed-out-by: Bart Van Assche <bvanassche@acm.org>
in http://marc.info/?l=linux-rdma&m=138763427730411&w=2

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
---
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/opensm/osm_db_files.c b/opensm/osm_db_files.c
index 38ee9a9..b43b5e6 100644
--- a/opensm/osm_db_files.c
+++ b/opensm/osm_db_files.c
@@ -475,16 +475,21 @@  int osm_db_store(IN osm_db_domain_t * p_domain,
 
 	p_domain_imp = (osm_db_domain_imp_t *) p_domain->p_domain_imp;
 
-	if (p_domain_imp->dirty == FALSE)
-		goto Exit;
-
 	p_tmp_file_name = malloc(sizeof(char) *
 				 (strlen(p_domain_imp->file_name) + 8));
+	if (!p_tmp_file_name) {
+		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6113: "
+			"Failed to allocate memory for temporary file name\n");
+		goto Exit;
+	}
 	strcpy(p_tmp_file_name, p_domain_imp->file_name);
 	strcat(p_tmp_file_name, ".tmp");
 
 	cl_spinlock_acquire(&p_domain_imp->lock);
 
+	if (p_domain_imp->dirty == FALSE)
+		goto Exit;
+
 	/* open up the output file */
 	p_file = fopen(p_tmp_file_name, "w");
 	if (!p_file) {