]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Backport recent memory fixes to 1.0
authorJames Golovich <james@gnuinter.net>
Mon, 25 Oct 2004 17:57:25 +0000 (17:57 +0000)
committerJames Golovich <james@gnuinter.net>
Mon, 25 Oct 2004 17:57:25 +0000 (17:57 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@4094 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c
channels/chan_sip.c
channels/chan_zap.c
channels/iax2-parser.c
res/res_monitor.c
res/res_odbc.c
tdd.c

index d6ebc6775b2e4596174d6d9d76ad66799c1d5012..70cb43410c34a7c34fa0cb5e32a980a57182f8c3 100755 (executable)
@@ -536,12 +536,12 @@ AST_MUTEX_DEFINE_STATIC(dpcache_lock);
 static void iax_debug_output(const char *data)
 {
        if (iaxdebug)
-               ast_verbose(data);
+               ast_verbose("%s", data);
 }
 
 static void iax_error_output(const char *data)
 {
-       ast_log(LOG_WARNING, data);
+       ast_log(LOG_WARNING, "%s", data);
 }
 
 /* XXX We probably should use a mutex when working with this XXX */
@@ -6399,9 +6399,11 @@ static struct iax2_peer *build_peer(char *name, struct ast_variable *v)
        } else {
                ast_mutex_unlock(&peerl.lock);
                peer = malloc(sizeof(struct iax2_peer));
-               memset(peer, 0, sizeof(struct iax2_peer));
-               peer->expire = -1;
-               peer->pokeexpire = -1;
+               if (peer) {
+                       memset(peer, 0, sizeof(struct iax2_peer));
+                       peer->expire = -1;
+                       peer->pokeexpire = -1;
+               }
        }
        if (peer) {
                peer->messagedetail = globalmessagedetail;
@@ -6566,7 +6568,8 @@ static struct iax2_user *build_user(char *name, struct ast_variable *v)
        } else {
                ast_mutex_unlock(&userl.lock);
                user = malloc(sizeof(struct iax2_user));
-               memset(user, 0, sizeof(struct iax2_user));
+               if (user)
+                       memset(user, 0, sizeof(struct iax2_user));
        }
        
        if (user) {
index 63e8f293620d972452304a0795d6f33177978faf..e6fa494503ce028def13c470cbfde2f5af2f2a94 100755 (executable)
@@ -8222,6 +8222,8 @@ static struct sip_peer *temp_peer(char *name)
 {
        struct sip_peer *peer;
        peer = malloc(sizeof(struct sip_peer));
+       if (!peer)
+               return NULL;
        memset(peer, 0, sizeof(struct sip_peer));
        peer->expire = -1;
        peer->pokeexpire = -1;
@@ -8282,12 +8284,14 @@ static struct sip_peer *build_peer(char *name, struct ast_variable *v)
        } else {
                ast_mutex_unlock(&peerl.lock);
                peer = malloc(sizeof(struct sip_peer));
-               memset(peer, 0, sizeof(struct sip_peer));
-               peer->expire = -1;
-               peer->pokeexpire = -1;
+               if (peer) {
+                       memset(peer, 0, sizeof(struct sip_peer));
+                       peer->expire = -1;
+                       peer->pokeexpire = -1;
+               }
        }
-       peer->lastmsgssent = -1;
        if (peer) {
+               peer->lastmsgssent = -1;
                if (!found) {
                        strncpy(peer->name, name, sizeof(peer->name)-1);
                        strncpy(peer->context, default_context, sizeof(peer->context)-1);
index 77416d13579da039af2fd838155b863ddffd1870..efe6e39f9c6a0d11e6a88debdfbd5f197e022b6a 100755 (executable)
@@ -7125,7 +7125,7 @@ static void *do_idle_thread(void *vchan)
 
 static void zt_pri_message(char *s)
 {
-       ast_verbose(s);
+       ast_verbose("%s", s);
 }
 
 static void zt_pri_error(char *s)
index c54af66a5f725cbbf74396f289883e24ed94cf8c..34f251fb04df2e93a744df7772ec51f876d523c3 100755 (executable)
@@ -32,7 +32,7 @@ static int oframes = 0;
 
 static void internaloutput(const char *str)
 {
-       printf(str);
+       fputs(str, stdout);
 }
 
 static void internalerror(const char *str)
index c36460c5a7a8e85dbbf683ab96610317c80c938d..2a0b00fa4b6131c394481d53fb411c73996d18e2 100755 (executable)
@@ -90,6 +90,11 @@ int ast_monitor_start(       struct ast_channel *chan, const char *format_spec,
                }
 
                monitor = malloc(sizeof(struct ast_channel_monitor));
+               if (!monitor) {
+                       if (need_lock)
+                               ast_mutex_unlock(&chan->lock);
+                       return -1;
+               }
                memset(monitor, 0, sizeof(struct ast_channel_monitor));
 
                /* Determine file names */
@@ -391,6 +396,11 @@ static int start_monitor_action(struct mansession *s, struct message *m)
        if ((!fname) || (ast_strlen_zero(fname))) {
                // No filename base specified, default to channel name as per CLI
                fname = malloc (FILENAME_MAX);
+               if (!fname) {
+                       astman_send_error(s, m, "Could not start monitoring channel");
+                       ast_mutex_unlock(&c->lock);
+                       return 0;
+               }
                memset(fname, 0, FILENAME_MAX);
                strncpy(fname, c->name, FILENAME_MAX-1);
                // Channels have the format technology/channel_name - have to replace that / 
index c8efb062014988b1f567f860d3f1ad3a49bd1ebc..f1697ee62ea9f94fc06d5039e65b0fbee8808df0 100755 (executable)
@@ -99,10 +99,12 @@ static int load_odbc_config(void)
                        if (!strcmp(cat, "ENV")) {
                                for (v = ast_variable_browse(config, cat); v; v = v->next) {
                                        env_var = malloc(strlen(v->name) + strlen(v->value) + 2);
-                                       sprintf(env_var, "%s=%s", v->name, v->value);
-                                       ast_log(LOG_NOTICE, "Adding ENV var: %s=%s\n", v->name, v->value);
-                                       putenv(env_var);
-                                       free(env_var);
+                                       if (env_var) {
+                                               sprintf(env_var, "%s=%s", v->name, v->value);
+                                               ast_log(LOG_NOTICE, "Adding ENV var: %s=%s\n", v->name, v->value);
+                                               putenv(env_var);
+                                               free(env_var);
+                                       }
                                }
 
                        cat = ast_category_browse(config, cat);
@@ -222,6 +224,8 @@ odbc_obj *new_odbc_obj(char *name, char *dsn, char *username, char *password)
        static odbc_obj *new;
 
        new = malloc(sizeof(odbc_obj));
+       if (!new)
+               return NULL;
        memset(new, 0, sizeof(odbc_obj));
        new->env = SQL_NULL_HANDLE;
 
diff --git a/tdd.c b/tdd.c
index 6ff6c0fbd0995106f89524307c253c515be3ec12..e2a6cc839ccc0db3088c31c16b57dca218e3c0b7 100755 (executable)
--- a/tdd.c
+++ b/tdd.c
@@ -77,8 +77,8 @@ struct tdd_state *tdd_new(void)
 {
        struct tdd_state *tdd;
        tdd = malloc(sizeof(struct tdd_state));
-       memset(tdd, 0, sizeof(struct tdd_state));
        if (tdd) {
+               memset(tdd, 0, sizeof(struct tdd_state));
                tdd->fskd.spb = 176;            /* 45.5 baud */
                tdd->fskd.hdlc = 0;             /* Async */
                tdd->fskd.nbit = 5;             /* 5 bits */