ldap: free in case of error cases
authorDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 27 Jul 2017 11:08:19 +0000 (13:08 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 27 Jul 2017 11:08:19 +0000 (13:08 +0200)
src/modules/ldap/ld_session.c
src/modules/ldap/ldap_mod.c

index 25ad429..8a27d08 100644 (file)
@@ -62,6 +62,7 @@ int add_ld_session(char* _name, LDAP* _ldh, dictionary* _d)
        new_lds->host_name = (char*)pkg_malloc(strlen(host_name)+1);
        if (new_lds->host_name == NULL) {
                LM_ERR("no memory\n");
+               pkg_free(new_lds);
                return -1;
        }
        strcpy(new_lds->host_name, host_name);
@@ -117,6 +118,8 @@ int add_ld_session(char* _name, LDAP* _ldh, dictionary* _d)
        new_lds->bind_dn = (char*)pkg_malloc(strlen(bind_dn)+1);
        if (new_lds->bind_dn == NULL) {
                LM_ERR("no memory\n");
+               pkg_free(new_lds->host_name);
+               pkg_free(new_lds);
                return -1;
        }
        strcpy(new_lds->bind_dn, bind_dn);
@@ -129,6 +132,9 @@ int add_ld_session(char* _name, LDAP* _ldh, dictionary* _d)
        new_lds->bind_pwd = (char*)pkg_malloc(strlen(bind_pwd)+1);
        if (new_lds->bind_pwd == NULL) {
                LM_ERR("no memory\n");
+               pkg_free(new_lds->bind_dn);
+               pkg_free(new_lds->host_name);
+               pkg_free(new_lds);
                return -1;
        }
        strcpy(new_lds->bind_pwd, bind_pwd);
index 89eb89c..59367a8 100644 (file)
@@ -447,6 +447,7 @@ static int ldap_result_check_fixup(void** param, int param_no)
                        if (pv_parse_format(&s, &(lp->check_str_elem_p)) < 0)
                        {
                                LM_ERR("pv_parse_format failed\n");
+                               pkg_free(lp);
                                return E_OUT_OF_MEM;
                        }
                }