[asterisk-commits] jrose: branch 1.8 r358214 - /branches/1.8/main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 5 12:50:04 CST 2012


Author: jrose
Date: Mon Mar  5 12:49:58 2012
New Revision: 358214

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=358214
Log:
Eliminate double close of file descriptor in manager.c

The process_output function in manager.c attempted to call fclose and close immediately
afterwards. Since fclose implies close, this resulted in a potential double free on file
descriptors. This patch changes that behavior and also adds error checking to fclose and
close depending on which was deemed necessary. Also error messages. Thanks to Rosen
Iliev for pointing out the location of the problem.

(closes issue ASTERISK-18453)
Reported By: Jaco Kroon
Review: https://reviewboard.asterisk.org/r/1793/

Modified:
    branches/1.8/main/manager.c

Modified: branches/1.8/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/manager.c?view=diff&rev=358214&r1=358213&r2=358214
==============================================================================
--- branches/1.8/main/manager.c (original)
+++ branches/1.8/main/manager.c Mon Mar  5 12:49:58 2012
@@ -5698,10 +5698,20 @@
 		xml_translate(out, "", params, format);
 	}
 
-	fclose(s->f);
-	s->f = NULL;
-	close(s->fd);
-	s->fd = -1;
+	if (s->f) {
+		if (fclose(s->f)) {
+			ast_log(LOG_ERROR, "fclose() failed: %s\n", strerror(errno));
+		}
+		s->f = NULL;
+		s->fd = -1;
+	} else if (s->fd != -1) {
+		if (close(s->fd)) {
+			ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno));
+		}
+		s->fd = -1;
+	} else {
+		ast_log(LOG_ERROR, "process output attempted to close file/file descriptor on mansession without a valid file or file descriptor.\n");
+	}
 }
 
 static int generic_http_callback(struct ast_tcptls_session_instance *ser,




More information about the asterisk-commits mailing list