]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
fix: memory and resource leaks 50/3050/1
authorAlexei Gradinari <alex2grad@gmail.com>
Mon, 20 Jun 2016 20:09:05 +0000 (16:09 -0400)
committerAlexei Gradinari <alex2grad@gmail.com>
Mon, 20 Jun 2016 20:09:05 +0000 (16:09 -0400)
ASTERISK-26119 #close

Change-Id: Iecbf7d0f360a021147344c4e83ab242fd1e7512c

main/ast_expr2.c
main/ast_expr2.y
res/ael/pval.c
res/res_phoneprov.c

index a9e4eff442dcbfc56233b22acfc007ddd1e0c63d..781abd95a9c03506064f0017225e78d6b066e3be 100644 (file)
@@ -3668,13 +3668,20 @@ op_tildetilde (struct val *a, struct val *b)
        /* strip double quotes from both -- */
        strip_quotes(a);
        strip_quotes(b);
-       
+
        vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
+       if (vs == NULL) {
+               ast_log(LOG_WARNING, "malloc() failed\n");
+               return NULL;
+       }
+
        strcpy(vs,a->u.s);
        strcat(vs,b->u.s);
 
        v = make_str(vs);
 
+       free(vs);
+
        /* free arguments */
        free_value(a);
        free_value(b);
index 869dfe9ea9656a0b03b039e9a6d67730b5d9fc24..913bc2662e4c1b35d488bbe1002914f3324803aa 100644 (file)
@@ -1661,13 +1661,20 @@ op_tildetilde (struct val *a, struct val *b)
        /* strip double quotes from both -- */
        strip_quotes(a);
        strip_quotes(b);
-       
+
        vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
+       if (vs == NULL) {
+               ast_log(LOG_WARNING, "malloc() failed\n");
+               return NULL;
+       }
+
        strcpy(vs,a->u.s);
        strcat(vs,b->u.s);
 
        v = make_str(vs);
 
+       free(vs);
+
        /* free arguments */
        free_value(a);
        free_value(b);
index c0da0f03ff725780a9b64d6b6702cad5a8343f8d..441e14a2d55efd976a9d810aa84bff4b153f87d7 100644 (file)
@@ -3356,9 +3356,9 @@ static int gen_prios(struct ael_extension *exten, char *label, pval *statement,
 #ifdef OLD_RAND_ACTION
        struct ael_priority *rand_test, *rand_end, *rand_skip;
 #endif
-       char *buf1;
-       char *buf2;
-       char *new_label;
+       RAII_VAR(char *, buf1, NULL, free);
+       RAII_VAR(char *, buf2, NULL, free);
+       RAII_VAR(char *, new_label, NULL, free);
        char *strp, *strp2;
        int default_exists;
        int local_control_statement_count;
@@ -4216,9 +4216,6 @@ static int gen_prios(struct ael_extension *exten, char *label, pval *statement,
                        break;
                }
        }
-       free(buf1);
-       free(buf2);
-       free(new_label);
        return 0;
 }
 
@@ -5081,7 +5078,10 @@ int  pvalCheckType( pval *p, char *funcname, pvaltype type )
 pval *pvalCreateNode( pvaltype type )
 {
        pval *p = calloc(1,sizeof(pval)); /* why, oh why, don't I use ast_calloc? Way, way, way too messy if I do! */
-       p->type = type;                   /* remember, this can be used externally or internally to asterisk */
+                                         /* remember, this can be used externally or internally to asterisk */
+       if (p) {
+               p->type = type;
+       }
        return p;
 }
 
@@ -5442,14 +5442,30 @@ void pvalIncludesAddInclude( pval *p, const char *include )
 
 void pvalIncludesAddIncludeWithTimeConstraints( pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range )
 {
-       pval *hr = pvalCreateNode(PV_WORD);
-       pval *dom = pvalCreateNode(PV_WORD);
-       pval *dow = pvalCreateNode(PV_WORD);
-       pval *mon = pvalCreateNode(PV_WORD);
-       pval *s = pvalCreateNode(PV_WORD);
-       
-       if (!pvalCheckType(p, "pvalIncludeAddIncludeWithTimeConstraints", PV_INCLUDES))
+       pval *hr;
+       pval *dom;
+       pval *dow;
+       pval *mon;
+       pval *s;
+
+       if (!pvalCheckType(p, "pvalIncludeAddIncludeWithTimeConstraints", PV_INCLUDES)) {
+               return;
+       }
+
+       hr = pvalCreateNode(PV_WORD);
+       dom = pvalCreateNode(PV_WORD);
+       dow = pvalCreateNode(PV_WORD);
+       mon = pvalCreateNode(PV_WORD);
+       s = pvalCreateNode(PV_WORD);
+
+       if (!hr || !dom || !dow || !mon || !s) {
+               destroy_pval(hr);
+               destroy_pval(dom);
+               destroy_pval(dow);
+               destroy_pval(mon);
+               destroy_pval(s);
                return;
+       }
 
        s->u1.str = (char *)include;
        p->u1.list = linku1(p->u1.list, s);
@@ -5696,12 +5712,28 @@ char* pvalIfGetCondition( pval *p )
 
 void pvalIfTimeSetCondition( pval *p, char *hour_range, char *dow_range, char *dom_range, char *mon_range )  /* time range format: 24-hour format begin-end|dow range|dom range|month range */
 {
-       pval *hr = pvalCreateNode(PV_WORD);
-       pval *dow = pvalCreateNode(PV_WORD);
-       pval *dom = pvalCreateNode(PV_WORD);
-       pval *mon = pvalCreateNode(PV_WORD);
-       if (!pvalCheckType(p, "pvalIfTimeSetCondition", PV_IFTIME))
+       pval *hr;
+       pval *dow;
+       pval *dom;
+       pval *mon;
+
+       if (!pvalCheckType(p, "pvalIfTimeSetCondition", PV_IFTIME)) {
                return;
+       }
+
+       hr = pvalCreateNode(PV_WORD);
+       dow = pvalCreateNode(PV_WORD);
+       dom = pvalCreateNode(PV_WORD);
+       mon = pvalCreateNode(PV_WORD);
+
+       if (!hr || !dom || !dow || !mon) {
+               destroy_pval(hr);
+               destroy_pval(dom);
+               destroy_pval(dow);
+               destroy_pval(mon);
+               return;
+       }
+
        pvalWordSetString(hr, hour_range);
        pvalWordSetString(dow, dow_range);
        pvalWordSetString(dom, dom_range);
index 4ae7efe8fed1e4907e17016bb0e2dd11a0ef12ae..ef2fa93ad21eea7710ad50e7d983b41cba200bd8 100644 (file)
@@ -327,10 +327,13 @@ static int load_file(const char *filename, char **ret)
        fseek(f, 0, SEEK_END);
        len = ftell(f);
        fseek(f, 0, SEEK_SET);
-       if (!(*ret = ast_malloc(len + 1)))
+       if (!(*ret = ast_malloc(len + 1))) {
+               fclose(f);
                return -2;
+       }
 
        if (len != fread(*ret, sizeof(char), len, f)) {
+               fclose(f);
                free(*ret);
                *ret = NULL;
                return -3;