[svn-commits] rizzo: branch rizzo/video_v2 r87723 - in /team/rizzo/video_v2: channels/ incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Oct 30 17:05:59 CDT 2007


Author: rizzo
Date: Tue Oct 30 17:05:59 2007
New Revision: 87723

URL: http://svn.digium.com/view/asterisk?view=rev&rev=87723
Log:
Implement part of the stringfield modifications suggested
on the -dev list, namely:
+ new api ast_string_field_free_memory replaces
  the previous ast_string_field_free_all() and
  ast_string_field_free_pools()
+ remove ast_string_field_free(), use ast_string_field_set()
  with a NULL argument. Fix the function to handle a NULL;
+ leave ast_string_field_free_all() defined for the time being,
  as there is one place (in chan_sip.c) where it is actually
  used properly, to cleanup an ast_threadstorage object across calls.
  This will need further work however, because a side effect of this
  usage pattern is that it will effectively leak memory


Modified:
    team/rizzo/video_v2/channels/chan_iax2.c
    team/rizzo/video_v2/channels/chan_sip.c
    team/rizzo/video_v2/include/asterisk/stringfields.h
    team/rizzo/video_v2/main/channel.c
    team/rizzo/video_v2/res/res_features.c

Modified: team/rizzo/video_v2/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/chan_iax2.c?view=diff&rev=87723&r1=87722&r2=87723
==============================================================================
--- team/rizzo/video_v2/channels/chan_iax2.c (original)
+++ team/rizzo/video_v2/channels/chan_iax2.c Tue Oct 30 17:05:59 2007
@@ -2155,7 +2155,7 @@
 				iax2_frame_free(frame.data);
 			jb_destroy(pvt->jb);
 			/* gotta free up the stringfields */
-			ast_string_field_free_pools(pvt);
+			ast_string_field_free_memory(pvt);
 			ast_free(pvt);
 		}
 	}
@@ -9409,7 +9409,7 @@
 	if (peer->mwi_event_sub)
 		ast_event_unsubscribe(peer->mwi_event_sub);
 
-	ast_string_field_free_pools(peer);
+	ast_string_field_free_memory(peer);
 }
 
 /*! \brief Create peer structure based on configuration */
@@ -9661,7 +9661,7 @@
 		ast_variables_destroy(user->vars);
 		user->vars = NULL;
 	}
-	ast_string_field_free_pools(user);
+	ast_string_field_free_memory(user);
 }
 
 /*! \brief Create in-memory user structure from configuration */
@@ -9702,7 +9702,7 @@
 	
 	if (user) {
 		if (firstpass) {
-			ast_string_field_free_pools(user);
+			ast_string_field_free_memory(user);
 			memset(user, 0, sizeof(struct iax2_user));
 			if (ast_string_field_init(user, 32)) {
 				user = user_unref(user);

Modified: team/rizzo/video_v2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/chan_sip.c?view=diff&rev=87723&r1=87722&r2=87723
==============================================================================
--- team/rizzo/video_v2/channels/chan_sip.c (original)
+++ team/rizzo/video_v2/channels/chan_sip.c Tue Oct 30 17:05:59 2007
@@ -3601,7 +3601,7 @@
 		ast_sched_del(sched, reg->expire);
 	if (reg->timeout > -1)
 		ast_sched_del(sched, reg->timeout);
-	ast_string_field_free_pools(reg);
+	ast_string_field_free_memory(reg);
 	regobjs--;
 	ast_free(reg);
 	
@@ -3708,7 +3708,7 @@
 	}
 	ast_mutex_destroy(&p->pvt_lock);
 
-	ast_string_field_free_pools(p);
+	ast_string_field_free_memory(p);
 
 	ast_free(p);
 }
@@ -6454,7 +6454,7 @@
 
 	if (!ast_strlen_zero(p->url)) {
 		add_header(resp, "Access-URL", p->url);
-		ast_string_field_free(p, url);
+		ast_string_field_set(p, url, NULL);
 	}
 
 	return 0;
@@ -6564,7 +6564,7 @@
 
 	if (!ast_strlen_zero(p->url)) {
 		add_header(req, "Access-URL", p->url);
-		ast_string_field_free(p, url);
+		ast_string_field_set(p, url, NULL);
 	}
 
 	return 0;
@@ -6606,7 +6606,7 @@
 {
 	struct sip_pvt *p = data;
 
-	ast_string_field_free_pools(p);
+	ast_string_field_free_memory(p);
 
 	ast_free(data);
 }
@@ -6656,7 +6656,7 @@
 	__transmit_response(p, msg, req, XMIT_UNRELIABLE);
 
 	/* Free the string fields, but not the pool space */
-	ast_string_field_free_all(p);
+	ast_string_field_free_strings(p);
 
 	return 0;
 }
@@ -8175,7 +8175,7 @@
 		} else {
 			p = r->call;
 			make_our_tag(p->tag, sizeof(p->tag));	/* create a new local tag for every register attempt */
-			ast_string_field_free(p, theirtag);	/* forget their old tag, so we don't match tags when getting response */
+			ast_string_field_set(p, theirtag, NULL);	/* forget their old tag, so we don't match tags when getting response */
 		}
 	} else {
 		/* Build callid for registration if we haven't registered before */
@@ -10219,8 +10219,8 @@
 		p->timer_t1 = peer->lastms;
 	if (ast_test_flag(&peer->flags[0], SIP_INSECURE_INVITE)) {
 		/* Pretend there is no required authentication */
-		ast_string_field_free(p, peersecret);
-		ast_string_field_free(p, peermd5secret);
+		ast_string_field_set(p, peersecret, NULL);
+		ast_string_field_set(p, peermd5secret, NULL);
 	}
 	if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, req->ignore))) {
 		ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
@@ -13157,7 +13157,7 @@
 			p->options->auth_type = resp;
 
 		/* Then we AUTH */
-		ast_string_field_free(p, theirtag);	/* forget their old tag, so we don't match tags when getting response */
+		ast_string_field_set(p, theirtag, NULL);	/* forget their old tag, so we don't match tags when getting response */
 		if (!req->ignore) {
 			if (p->authtries < MAX_AUTHTRIES)
 				p->invitestate = INV_CALLING;
@@ -14715,7 +14715,7 @@
 			}
 			p->invitestate = INV_COMPLETED;	
 			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
-			ast_string_field_free(p, theirtag);
+			ast_string_field_set(p, theirtag, NULL);
 			return 0;
 		}
 
@@ -16831,7 +16831,7 @@
 	   SIP/peername will still use the full contact */
 	if (ext) {
 		ast_string_field_set(p, username, ext);
-		ast_string_field_free(p, fullcontact);
+		ast_string_field_set(p, fullcontact, NULL);
 	}
 #if 0
 	printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host);

Modified: team/rizzo/video_v2/include/asterisk/stringfields.h
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/include/asterisk/stringfields.h?view=diff&rev=87723&r1=87722&r2=87723
==============================================================================
--- team/rizzo/video_v2/include/asterisk/stringfields.h (original)
+++ team/rizzo/video_v2/include/asterisk/stringfields.h Tue Oct 30 17:05:59 2007
@@ -45,10 +45,10 @@
   \code
   struct sample_fields *sample;
   
-  sample = calloc(1, sizeof(*sample));
+  sample = ast_calloc(1, sizeof(*sample));
   if (sample) {
 	  if (ast_string_field_init(sample, 256)) {
-		  free(sample);
+		  ast_free(sample);
 		  sample = NULL;
 	  }
   }
@@ -59,8 +59,8 @@
   \endcode
   
   Fields will default to pointing to an empty string, and will
-  revert to that when ast_string_field_free() is called. This means
-  that a string field will \b never contain NULL.
+  revert to that when ast_string_field_set() is called with a NULL
+  argument: a string field will \b never contain NULL.
   
   Using the fields is much like using regular 'char *' fields
   in the structure, except that writing into them must be done
@@ -74,8 +74,8 @@
   and their storage pool must be freed:
   
   \code
-  ast_string_field_free_all(sample);
-  free(sample);
+  ast_string_field_memory(sample);
+  ast_free(sample);
   \endcode
 */
 
@@ -235,14 +235,15 @@
 */
 
 #define ast_string_field_index_set(x, index, data) do { 		\
-	size_t __dlen__ = strlen(data);					\
+	const char *__d__ = (data);					\
+	size_t __dlen__ = (__d__) ? strlen(__d__) : 0;				\
 	const char **__p__ = (const char **)&((x)->__field_mgr_pool) + 1 + index;	\
 	if (__dlen__ == 0)							\
 		*__p__ = __ast_string_field_empty;				\
 	else if (__dlen__ <= strlen(*__p__))					\
-		strcpy((char *)*__p__, data);					\
+		strcpy((char *)*__p__, __d__);					\
 	else if ( (*__p__ = __ast_string_field_alloc_space(&(x)->__field_mgr, &(x)->__field_mgr_pool, __dlen__ + 1) ) )	\
-		strcpy((char *)*__p__, data);					\
+		strcpy((char *)*__p__, __d__);					\
 	} while (0)
 
 /*!
@@ -305,35 +306,6 @@
 	__ast_string_field_index_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, ast_string_field_index(x, field), fmt, args1, args2)
 
 /*!
-  \brief Free a field's value.
-  \param x Pointer to a structure containing fields
-  \param index Index position of the field within the structure
-  \return nothing
-
-  \note Because of the storage pool used, the memory
-  occupied by the field's value is \b not recovered; the field
-  pointer is just changed to point to an empty string.
-*/
-#define ast_string_field_index_free(x, index) do { \
-	const char **__p__ = (const char **)&(x)->__field_mgr_pool + 1 + index;		\
-	*__p__ = __ast_string_field_empty; \
-	} while(0)
-
-/*!
-  \brief Free a field's value.
-  \param x Pointer to a structure containing fields
-  \param field Name of the field to free
-  \return nothing
-
-  \note Because of the storage pool used, the memory
-  occupied by the field's value is \b not recovered; the field
-  pointer is just changed to point to an empty string.
-*/
-#define ast_string_field_free(x, field) do {	\
-	ast_string_field_index_free(x, ast_string_field_index(x, field)) ;	\
-	} while (0)
-
-/*!
   \brief Free the stringfield storage pools attached to a structure
   \param x Pointer to a structure containing fields
   \return nothing.
@@ -342,14 +314,15 @@
   structure; it should only be called immediately before freeing
   the structure itself.
 */
-#define ast_string_field_free_pools(x) do {		\
+#define ast_string_field_free_memory(x) do {		\
 	struct ast_string_field_pool *this;		\
 	while ( (this = (x)->__field_mgr_pool)) {	\
 		(x)->__field_mgr_pool = this->prev;	\
-		free(this);				\
+		ast_free(this);				\
 	}						\
 	} while(0)
 
+#if 1	/* deprecated but not deleted yet */
 /*!
   \brief Free the stringfields in a structure
   \param x Pointer to a structure containing fields
@@ -359,12 +332,13 @@
   attached to the structure will be available for use by
   stringfields again.
 */
-#define ast_string_field_free_all(x) do {			\
+#define ast_string_field_free_strings(x) do {			\
 	const char **__p__ = (const char **)&(x)->__field_mgr_pool + 1;		\
 	while ((struct ast_string_field_mgr *)__p__ != &(x)->__field_mgr) \
 		*__p__++ = __ast_string_field_empty;		\
 	(x)->__field_mgr.used = 0;				\
 	(x)->__field_mgr.space = (x)->__field_mgr.size;		\
 	} while(0)
+#endif
 
 #endif /* _ASTERISK_STRINGFIELDS_H */

Modified: team/rizzo/video_v2/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/main/channel.c?view=diff&rev=87723&r1=87722&r2=87723
==============================================================================
--- team/rizzo/video_v2/main/channel.c (original)
+++ team/rizzo/video_v2/main/channel.c Tue Oct 30 17:05:59 2007
@@ -667,7 +667,7 @@
 	if (needqueue) {
 		if (pipe(tmp->alertpipe)) {
 			ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
-			ast_string_field_free_pools(tmp);
+			ast_string_field_free_memory(tmp);
 			ast_free(tmp);
 			return NULL;
 		} else {
@@ -1160,7 +1160,7 @@
 	/* Destroy the jitterbuffer */
 	ast_jb_destroy(chan);
 
-	ast_string_field_free_pools(chan);
+	ast_string_field_free_memory(chan);
 	ast_free(chan);
 	AST_RWLIST_UNLOCK(&channels);
 

Modified: team/rizzo/video_v2/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/res/res_features.c?view=diff&rev=87723&r1=87722&r2=87723
==============================================================================
--- team/rizzo/video_v2/res/res_features.c (original)
+++ team/rizzo/video_v2/res/res_features.c Tue Oct 30 17:05:59 2007
@@ -1259,11 +1259,11 @@
 	AST_RWLIST_WRLOCK(&feature_groups);
 	while ((fg = AST_LIST_REMOVE_HEAD(&feature_groups, entry))) {
 		while ((fge = AST_LIST_REMOVE_HEAD(&fg->features, entry))) {
-			ast_string_field_free_all(fge);
+			ast_string_field_free_memory(fge);
 			ast_free(fge);
 		}
 
-		ast_string_field_free_all(fg);
+		ast_string_field_free_memory(fg);
 		ast_free(fg);
 	}
 	AST_RWLIST_UNLOCK(&feature_groups);




More information about the svn-commits mailing list