Properly account for memory allocated for channels and datastores

As in previous commits, when channels are allocated (with ast_channel_alloc) or datastores are allocated (with ast_datastore_alloc) properly account for the memory being owned by the caller, instead of the allocator function itself.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@192318 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2009-05-05 10:34:19 +00:00
parent d8182202ef
commit ec5116f80c
6 changed files with 134 additions and 26 deletions

View File

@@ -28,7 +28,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/datastore.h"
#include "asterisk/utils.h"
struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
struct ast_datastore *__ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid,
const char *file, int line, const char *function)
{
struct ast_datastore *datastore = NULL;
@@ -37,11 +38,15 @@ struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info,
return NULL;
}
/* Allocate memory for datastore and clear it */
datastore = ast_calloc(1, sizeof(*datastore));
if (!datastore) {
#if defined(__AST_DEBUG_MALLOC)
if (!(datastore = __ast_calloc(1, sizeof(*datastore), file, line, function))) {
return NULL;
}
#else
if (!(datastore = ast_calloc(1, sizeof(*datastore)))) {
return NULL;
}
#endif
datastore->info = info;
@@ -71,3 +76,19 @@ int ast_datastore_free(struct ast_datastore *datastore)
return res;
}
/* DO NOT PUT ADDITIONAL FUNCTIONS BELOW THIS BOUNDARY
*
* ONLY FUNCTIONS FOR PROVIDING BACKWARDS ABI COMPATIBILITY BELONG HERE
*
*/
/* Provide binary compatibility for modules that call ast_datastore_alloc() directly;
* newly compiled modules will call __ast_datastore_alloc() via the macros in datastore.h
*/
#undef ast_datastore_alloc
struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
{
return __ast_datastore_alloc(info, uid, __FILE__, __LINE__, __FUNCTION__);
}