[asterisk-commits] rmudgett: trunk r342489 - in /trunk: ./ main/astobj2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 25 17:06:49 CDT 2011


Author: rmudgett
Date: Tue Oct 25 17:06:43 2011
New Revision: 342489

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342489
Log:
Check fopen return value for ao2 reference debug output.

Reported by: wdoekes
Patched by: wdoekes

Review: https://reviewboard.asterisk.org/r/1539/
........

Merged revisions 342487 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 342488 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/main/astobj2.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/astobj2.c?view=diff&rev=342489&r1=342488&r2=342489
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Tue Oct 25 17:06:43 2011
@@ -210,14 +210,19 @@
 		return -1;
 
 	if (delta != 0) {
-		FILE *refo = fopen(REF_FILE,"a");
-		fprintf(refo, "%p %s%d   %s:%d:%s (%s) [@%d]\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag, obj ? obj->priv_data.ref_counter : -1);
-		fclose(refo);
+		FILE *refo = fopen(REF_FILE, "a");
+		if (refo) {
+			fprintf(refo, "%p %s%d   %s:%d:%s (%s) [@%d]\n", user_data, (delta < 0 ? "" : "+"),
+				delta, file, line, funcname, tag, obj ? obj->priv_data.ref_counter : -1);
+			fclose(refo);
+		}
 	}
 	if (obj->priv_data.ref_counter + delta == 0 && obj->priv_data.destructor_fn != NULL) { /* this isn't protected with lock; just for o/p */
-			FILE *refo = fopen(REF_FILE,"a"); 	 
-			fprintf(refo, "%p **call destructor** %s:%d:%s (%s)\n", user_data, file, line, funcname, tag); 	 
+		FILE *refo = fopen(REF_FILE, "a");
+		if (refo) {
+			fprintf(refo, "%p **call destructor** %s:%d:%s (%s)\n", user_data, file, line, funcname, tag);
 			fclose(refo);
+		}
 	}
 	return internal_ao2_ref(user_data, delta);
 }
@@ -319,14 +324,13 @@
 {
 	/* allocation */
 	void *obj;
-	FILE *refo = ref_debug ? fopen(REF_FILE,"a") : NULL;
+	FILE *refo;
 
 	if ((obj = internal_ao2_alloc(data_size, destructor_fn, file, line, funcname)) == NULL) {
-		fclose(refo);
-		return NULL;
-	}
-
-	if (refo) {
+		return NULL;
+	}
+
+	if (ref_debug && (refo = fopen(REF_FILE, "a"))) {
 		fprintf(refo, "%p =1   %s:%d:%s (%s)\n", obj, file, line, funcname, tag);
 		fclose(refo);
 	}




More information about the asterisk-commits mailing list