app_python: dname is always allocated in system memory
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 2 Nov 2016 14:21:28 +0000 (15:21 +0100)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 2 Nov 2016 14:21:28 +0000 (15:21 +0100)
- pointing it to static string will crash the free at shutdown

modules/app_python/app_python_mod.c

index 02ff097..9fd6264 100644 (file)
@@ -122,8 +122,20 @@ static int mod_init(void)
        }
 
        dname = strdup(dirname(dname_src));
-       if (strlen(dname) == 0)
-               dname = ".";
+       if(dname==NULL) {
+               LM_ERR("no more system memory\n");
+               return -1;
+       }
+       if (strlen(dname) == 0) {
+               free(dname);
+               dname = malloc(2);
+               if(dname==NULL) {
+                       LM_ERR("no more system memory\n");
+                       return -1;
+               }
+               dname[0] = '.';
+               dname[1] = '\0';
+       }
        bname = strdup(basename(bname_src));
        i = strlen(bname);
        if (bname[i - 1] == 'c' || bname[i - 1] == 'o')