[asterisk-commits] file: branch file/sorcery r378208 - /team/file/sorcery/main/sorcery.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 28 07:15:34 CST 2012


Author: file
Date: Fri Dec 28 07:15:29 2012
New Revision: 378208

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378208
Log:
Fix a potential race condition by setting the wizard on an object before it is created. It was possible previously for the value be set after another thread had retrieved the object.

Modified:
    team/file/sorcery/main/sorcery.c

Modified: team/file/sorcery/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/main/sorcery.c?view=diff&rev=378208&r1=378207&r2=378208
==============================================================================
--- team/file/sorcery/main/sorcery.c (original)
+++ team/file/sorcery/main/sorcery.c Fri Dec 28 07:15:29 2012
@@ -847,8 +847,16 @@
 static int sorcery_wizard_create(void *obj, void *arg, int flags)
 {
 	struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return !object_wizard->wizard->create(object_wizard->data, arg) ? CMP_MATCH | CMP_STOP : 0;
+	struct ast_sorcery_object_details *details = arg;
+
+	details->wizard = object_wizard;
+
+	if (object_wizard->wizard->create(object_wizard->data, arg)) {
+		details->wizard = NULL;
+		return 0;
+	}
+
+	return CMP_MATCH | CMP_STOP;
 }
 
 int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
@@ -861,13 +869,9 @@
 		return -1;
 	}
 
-	if ((object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_create, object))) {
-		/* Object was successfully created by the wizard so update the object details to reflect it */
-		details->wizard = object_wizard;
-		return 0;
-	} else {
-		return -1;
-	}
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_create, object);
+
+	return object_wizard ? 0 : -1;
 }
 
 int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)




More information about the asterisk-commits mailing list