[Asterisk-code-review] stringfields: Remove MALLOC DEBUG fields from struct ast str... (asterisk[master])

Corey Farrell asteriskteam at digium.com
Tue Mar 13 15:33:07 CDT 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/8517


Change subject: stringfields: Remove MALLOC_DEBUG fields from struct ast_string_field_mgr.
......................................................................

stringfields: Remove MALLOC_DEBUG fields from struct ast_string_field_mgr.

This causes MALLOC_DEBUG reporting to be slightly different, calls which
cause additional memory pools to be allocated now report the callers
location rather than the location which originally allocated the
string field structure.  This reduces storage needed by string fields
and allows MALLOC_DEBUG to identify the source of additional allocations
rather than obscuring it by reporting the original allocation caller.

Change-Id: Idd18e6639a87ab862079b580c114d90361412289
---
M include/asterisk/stringfields.h
M main/stringfields.c
2 files changed, 39 insertions(+), 39 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/8517/1

diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h
index 5ac5e09..edafb22 100644
--- a/include/asterisk/stringfields.h
+++ b/include/asterisk/stringfields.h
@@ -228,11 +228,6 @@
 	ast_string_field last_alloc;			/*!< the last field allocated */
 	struct ast_string_field_pool *embedded_pool;	/*!< pointer to the embedded pool, if any */
 	struct ast_string_field_vector string_fields;	/*!< field vector for compare and copy */
-	/* v-- MALLOC_DEBUG information */
-	const char *owner_file;				/*!< filename of owner */
-	const char *owner_func;				/*!< function name of owner */
-	int owner_line;					/*!< line number of owner */
-	/* ^-- MALLOC_DEBUG information */
 };
 
 /*!
@@ -266,7 +261,8 @@
   an additional pool will be allocated.
 */
 ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,
-						struct ast_string_field_pool **pool_head, size_t needed);
+	struct ast_string_field_pool **pool_head, size_t needed,
+	const char *file, int lineno, const char *func);
 
 /*!
   \internal
@@ -277,9 +273,9 @@
   \param format printf-style format string
   \return nothing
 */
-void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
-				  struct ast_string_field_pool **pool_head,
-				  ast_string_field *ptr, const char *format, ...) __attribute__((format(printf, 4, 5)));
+void __ast_string_field_ptr_build(const char *file, int lineno, const char *func,
+	struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head,
+	ast_string_field *ptr, const char *format, ...) __attribute__((format(printf, 7, 8)));
 
 /*!
   \internal
@@ -292,8 +288,9 @@
   \return nothing
 */
 void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
-				     struct ast_string_field_pool **pool_head,
-				     ast_string_field *ptr, const char *format, va_list ap) __attribute__((format(printf, 4, 0)));
+	struct ast_string_field_pool **pool_head,
+	ast_string_field *ptr, const char *format, va_list ap,
+	const char *file, int lineno, const char *func) __attribute__((format(printf, 4, 0)));
 
 /*!
   \brief Declare a string field
@@ -479,7 +476,7 @@
 	__res__; \
 })
 
-#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data)               \
+#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func) \
 ({                                                                                             \
     int __res__ = 0;                                                                           \
     const char *__d__ = (data);                                                                \
@@ -491,7 +488,7 @@
         *__p__ = __ast_string_field_empty;                                                     \
     } else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) ||                            \
            (!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) ||     \
-           (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__))) { \
+           (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__, file, lineno, func))) { \
         if (target != *__p__) {                                                                \
             __ast_string_field_release_active(field_mgr_pool, *__p__);                         \
             *__p__ = target;                                                                   \
@@ -502,6 +499,9 @@
     }                                                                                          \
     __res__;                                                                                   \
 })
+
+#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \
+	__ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
 /*!
   \brief Set a field to a simple string value
@@ -532,7 +532,8 @@
 ({ \
 	int __res__ = -1; \
 	if (((void *)(x)) != NULL) { \
-		__ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
+		__ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
+			&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
 		__res__ = 0; \
 	} \
 	__res__; \
@@ -550,7 +551,8 @@
 ({ \
 	int __res__ = -1; \
 	if (((void *)(x)) != NULL) { \
-		__ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
+		__ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
+			&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
 		__res__ = 0; \
 	} \
 	__res__; \
@@ -568,7 +570,8 @@
 ({ \
 	int __res__ = -1; \
 	if (((void *)(x)) != NULL) { \
-		__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
+		__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args, \
+			__FILE__, __LINE__, __PRETTY_FUNCTION__); \
 		__res__ = 0; \
 	} \
 	__res__; \
@@ -586,7 +589,8 @@
 ({ \
 	int __res__ = -1; \
 	if (((void *)(x)) != NULL) { \
-		__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
+		__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args, \
+			__FILE__, __LINE__, __PRETTY_FUNCTION__); \
 		__res__ = 0; \
 	} \
 	__res__; \
@@ -626,12 +630,14 @@
 	if (((void *)(copy)) != NULL && ((void *)(orig)) != NULL) { \
 		__res__ = __ast_string_fields_copy(((copy)->__field_mgr_pool), \
 			(struct ast_string_field_mgr *)&((copy)->__field_mgr), \
-			(struct ast_string_field_mgr *)&((orig)->__field_mgr)); \
+			(struct ast_string_field_mgr *)&((orig)->__field_mgr), \
+			__FILE__, __LINE__, __PRETTY_FUNCTION__); \
 	} \
 	__res__; \
 })
 
 int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
-	struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr);
+	struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr,
+	const char *file, int lineno, const char *func);
 
 #endif /* _ASTERISK_STRINGFIELDS_H */
diff --git a/main/stringfields.c b/main/stringfields.c
index 30aa8cd..0a9e599 100644
--- a/main/stringfields.c
+++ b/main/stringfields.c
@@ -179,11 +179,6 @@
 	}
 
 	mgr->last_alloc = NULL;
-	/* v-- MALLOC_DEBUG information */
-	mgr->owner_file = file;
-	mgr->owner_func = func;
-	mgr->owner_line = lineno;
-	/* ^-- MALLOC_DEBUG information */
 
 	if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {
 		return -1;
@@ -205,7 +200,8 @@
 }
 
 ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,
-	struct ast_string_field_pool **pool_head, size_t needed)
+	struct ast_string_field_pool **pool_head, size_t needed,
+	const char *file, int lineno, const char *func)
 {
 	char *result = NULL;
 	size_t space = (*pool_head)->size - (*pool_head)->used;
@@ -222,8 +218,7 @@
 			new_size *= 2;
 		}
 
-		if (add_string_pool(mgr, pool_head, new_size,
-			mgr->owner_file, mgr->owner_line, mgr->owner_func)) {
+		if (add_string_pool(mgr, pool_head, new_size, file, lineno, func)) {
 			return NULL;
 		}
 	}
@@ -290,7 +285,8 @@
 
 void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
 	struct ast_string_field_pool **pool_head, ast_string_field *ptr,
-	const char *format, va_list ap)
+	const char *format, va_list ap,
+	const char *file, int lineno, const char *func)
 {
 	size_t needed;
 	size_t available;
@@ -342,7 +338,8 @@
 		   (if it has one), or the space available in the pool (if it does not). allocate
 		   space for it, adding a new string pool if necessary.
 		*/
-		if (!(target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed))) {
+		target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed, file, lineno, func);
+		if (!target) {
 			return;
 		}
 		vsprintf(target, format, ap);
@@ -369,13 +366,14 @@
 	}
 }
 
-void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
+void __ast_string_field_ptr_build(const char *file, int lineno, const char *func,
+	struct ast_string_field_mgr *mgr,
 	struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, ...)
 {
 	va_list ap;
 
 	va_start(ap, format);
-	__ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap);
+	__ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap, file, lineno, func);
 	va_end(ap);
 }
 
@@ -419,11 +417,6 @@
 	mgr->embedded_pool = pool;
 	*pool_head = pool;
 	pool->size = size_to_alloc - struct_size - sizeof(*pool);
-	/* v-- MALLOC_DEBUG information */
-	mgr->owner_file = file;
-	mgr->owner_func = func;
-	mgr->owner_line = lineno;
-	/* ^-- MALLOC_DEBUG information */
 
 	return allocation;
 }
@@ -446,7 +439,8 @@
 }
 
 int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
-	struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr)
+	struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr,
+	const char *file, int lineno, const char *func)
 {
 	int i;
 	struct ast_string_field_vector *dest = &(copy_mgr->string_fields);
@@ -460,8 +454,8 @@
 	}
 
 	for (i = 0; i < AST_VECTOR_SIZE(dest); i++) {
-		if (ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),
-			*AST_VECTOR_GET(src, i))) {
+		if (__ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),
+			*AST_VECTOR_GET(src, i), file, lineno, func)) {
 			return -1;
 		}
 	}

-- 
To view, visit https://gerrit.asterisk.org/8517
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd18e6639a87ab862079b580c114d90361412289
Gerrit-Change-Number: 8517
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180313/1b26e465/attachment.html>


More information about the asterisk-code-review mailing list