summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorWalter Doekes <walter+asterisk@wjd.nu>2014-09-26 14:41:38 +0000
committerWalter Doekes <walter+asterisk@wjd.nu>2014-09-26 14:41:38 +0000
commit37179a2b1f0a12e063a2bb300e402ac5e7512569 (patch)
tree74872dbb405e8ef55370be0afe6bae8947a616da /main
parentb8c1130ed172e478d7eaccbf9ba2913aaf36b260 (diff)
core: Don't allow free to mean ast_free (and malloc, etc..).
This gets rid of most old libc free/malloc/realloc and replaces them with ast_free and friends. When compiling with MALLOC_DEBUG you'll notice it when you're mistakenly using one of the libc variants. For the legacy cases you can define WRAP_LIBC_MALLOC before including asterisk.h. Even better would be if the errors were also enabled when compiling without MALLOC_DEBUG, but that's a slightly more invasive header file change. Those compiling addons/format_mp3 will need to rerun ./contrib/scripts/get_mp3_source.sh. ASTERISK-24348 #related Review: https://reviewboard.asterisk.org/r/4015/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@423978 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/abstract_jb.c2
-rw-r--r--main/acl.c6
-rw-r--r--main/app.c10
-rw-r--r--main/ast_expr2.c1
-rw-r--r--main/ast_expr2.y1
-rw-r--r--main/ast_expr2f.c1
-rw-r--r--main/autoservice.c4
-rw-r--r--main/file.c13
-rw-r--r--main/hashtab.c3
-rw-r--r--main/loader.c2
-rw-r--r--main/tdd.c13
11 files changed, 28 insertions, 28 deletions
diff --git a/main/abstract_jb.c b/main/abstract_jb.c
index e4c3c76ed..c0e0429f3 100644
--- a/main/abstract_jb.c
+++ b/main/abstract_jb.c
@@ -857,7 +857,7 @@ void ast_jb_conf_default(struct ast_jb_conf *conf)
}
static void datastore_destroy_cb(void *data) {
- ast_free(data);
+ free(data);
ast_debug(1, "JITTERBUFFER datastore destroyed\n");
}
diff --git a/main/acl.c b/main/acl.c
index 5c3b633d7..a9f6c46a3 100644
--- a/main/acl.c
+++ b/main/acl.c
@@ -174,7 +174,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
}
bufsz = ifn.lifn_count * sizeof(struct lifreq);
- if (!(buf = malloc(bufsz))) {
+ if (!(buf = ast_malloc(bufsz))) {
close(s);
return -1;
}
@@ -187,7 +187,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
ifc.lifc_flags = 0;
if (ioctl(s, SIOCGLIFCONF, &ifc) < 0) {
close(s);
- free(buf);
+ ast_free(buf);
return -1;
}
@@ -201,7 +201,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
}
}
- free(buf);
+ ast_free(buf);
#endif /* SOLARIS */
close(s);
diff --git a/main/app.c b/main/app.c
index a6c7514cd..fd19beeaf 100644
--- a/main/app.c
+++ b/main/app.c
@@ -1892,7 +1892,7 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) {
if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
AST_RWLIST_REMOVE_CURRENT(group_list);
- free(gi);
+ ast_free(gi);
break;
}
}
@@ -1900,7 +1900,7 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
if (ast_strlen_zero(group)) {
/* Enable unsetting the group */
- } else if ((gi = calloc(1, len))) {
+ } else if ((gi = ast_calloc(1, len))) {
gi->chan = chan;
gi->group = (char *) gi + sizeof(*gi);
strcpy(gi->group, group);
@@ -2176,9 +2176,9 @@ static void path_lock_destroy(struct path_lock *obj)
close(obj->fd);
}
if (obj->path) {
- free(obj->path);
+ ast_free(obj->path);
}
- free(obj);
+ ast_free(obj);
}
static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
@@ -2222,7 +2222,7 @@ static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
return AST_LOCK_FAILURE;
}
pl->fd = fd;
- pl->path = strdup(path);
+ pl->path = ast_strdup(path);
time(&start);
while (
diff --git a/main/ast_expr2.c b/main/ast_expr2.c
index 798e3d3ce..f42604ee6 100644
--- a/main/ast_expr2.c
+++ b/main/ast_expr2.c
@@ -91,6 +91,7 @@
* $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
*/
+#define WRAP_LIBC_MALLOC
#include "asterisk.h"
#include <sys/types.h>
diff --git a/main/ast_expr2.y b/main/ast_expr2.y
index 83d3effe3..e8c68e333 100644
--- a/main/ast_expr2.y
+++ b/main/ast_expr2.y
@@ -12,6 +12,7 @@
* $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
*/
+#define WRAP_LIBC_MALLOC
#include "asterisk.h"
#include <sys/types.h>
diff --git a/main/ast_expr2f.c b/main/ast_expr2f.c
index 1f67d460d..51af56b40 100644
--- a/main/ast_expr2f.c
+++ b/main/ast_expr2f.c
@@ -1,3 +1,4 @@
+#define WRAP_LIBC_MALLOC
#include "asterisk.h"
#line 2 "ast_expr2f.c"
diff --git a/main/autoservice.c b/main/autoservice.c
index 305ab23b1..371464398 100644
--- a/main/autoservice.c
+++ b/main/autoservice.c
@@ -236,7 +236,7 @@ int ast_autoservice_start(struct ast_channel *chan)
/* There will only be a single member in the list at this point,
the one we just added. */
AST_LIST_REMOVE(&aslist, as, list);
- free(as);
+ ast_free(as);
asthread = AST_PTHREADT_NULL;
res = -1;
} else {
@@ -313,7 +313,7 @@ int ast_autoservice_stop(struct ast_channel *chan)
}
ast_channel_unlock(chan);
- free(as);
+ ast_free(as);
return res;
}
diff --git a/main/file.c b/main/file.c
index 1d3755ac2..4221b0851 100644
--- a/main/file.c
+++ b/main/file.c
@@ -412,17 +412,12 @@ static void filestream_destructor(void *arg)
}
}
- if (f->filename)
- free(f->filename);
- if (f->realfilename)
- free(f->realfilename);
+ ast_free(f->filename);
+ ast_free(f->realfilename);
if (f->vfs)
ast_closestream(f->vfs);
- if (f->write_buffer) {
- ast_free(f->write_buffer);
- }
- if (f->orig_chan_name)
- free((void *) f->orig_chan_name);
+ ast_free(f->write_buffer);
+ ast_free((void *)f->orig_chan_name);
ao2_cleanup(f->lastwriteformat);
ao2_cleanup(f->fr.subclass.format);
ast_module_unref(f->fmt->module);
diff --git a/main/hashtab.c b/main/hashtab.c
index d6cd7aa6d..4f52ec520 100644
--- a/main/hashtab.c
+++ b/main/hashtab.c
@@ -26,6 +26,7 @@
<support_level>core</support_level>
***/
+#define WRAP_LIBC_MALLOC
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -255,7 +256,7 @@ ast_hashtab_create
#else
if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) {
#endif
- free(ht);
+ ast_free(ht);
return NULL;
}
diff --git a/main/loader.c b/main/loader.c
index ac17ddc9e..def8bba2a 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -610,7 +610,7 @@ void ast_module_shutdown(void)
mod->info->unload();
}
AST_LIST_HEAD_DESTROY(&mod->users);
- free(mod);
+ ast_free(mod);
somethingchanged = 1;
}
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
diff --git a/main/tdd.c b/main/tdd.c
index a590e3b2f..eee3f0e73 100644
--- a/main/tdd.c
+++ b/main/tdd.c
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/ulaw.h"
#include "asterisk/tdd.h"
#include "asterisk/fskmodem.h"
+#include "asterisk/utils.h"
#include "ecdisa.h"
struct tdd_state {
@@ -104,7 +105,7 @@ void tdd_init(void)
struct tdd_state *tdd_new(void)
{
struct tdd_state *tdd;
- tdd = calloc(1, sizeof(*tdd));
+ tdd = ast_calloc(1, sizeof(*tdd));
if (tdd) {
#ifdef INTEGER_CALLERID
tdd->fskd.ispb = 176; /* 45.5 baud */
@@ -166,7 +167,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
int b = 'X';
int res;
int c,x;
- short *buf = calloc(1, 2 * len + tdd->oldlen);
+ short *buf = ast_calloc(1, 2 * len + tdd->oldlen);
short *obuf = buf;
if (!buf) {
ast_log(LOG_WARNING, "Out of memory\n");
@@ -182,13 +183,13 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
res = fsk_serial(&tdd->fskd, buf, &mylen, &b);
if (mylen < 0) {
ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
- free(obuf);
+ ast_free(obuf);
return -1;
}
buf += (olen - mylen);
if (res < 0) {
ast_log(LOG_NOTICE, "fsk_serial failed\n");
- free(obuf);
+ ast_free(obuf);
return -1;
}
if (res == 1) {
@@ -206,7 +207,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
tdd->oldlen = mylen * 2;
} else
tdd->oldlen = 0;
- free(obuf);
+ ast_free(obuf);
if (res) {
tdd->mode = 2;
/* put it in mode where it
@@ -218,7 +219,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
void tdd_free(struct tdd_state *tdd)
{
- free(tdd);
+ ast_free(tdd);
}
static inline float tdd_getcarrier(float *cr, float *ci, int bit)