s3:passdb: Don't leak memory on error in fetch_ldap_pw()
authorAndreas Schneider <asn@samba.org>
Thu, 9 Aug 2018 14:05:41 +0000 (16:05 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 10 Aug 2018 23:49:16 +0000 (01:49 +0200)
Found by covscan.

A candidate to use tallac ...

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13567

Pair-Programmed-With: Justin Stephenson <jstephen@redhat.com>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/passdb/secrets.c

index 7533d6b842f2189cf1fd7b6936140ec45cc1f9bb..ce215b1f2b2885c087c2b48e54f8eb3ce4034451 100644 (file)
@@ -351,6 +351,8 @@ bool fetch_ldap_pw(char **dn, char** pw)
 
                if (!old_style_key) {
                        DEBUG(0, ("fetch_ldap_pw: strdup failed!\n"));
+                       SAFE_FREE(*pw);
+                       SAFE_FREE(*dn);
                        return False;
                }
 
@@ -361,6 +363,7 @@ bool fetch_ldap_pw(char **dn, char** pw)
                if ((data == NULL) || (size < sizeof(old_style_pw))) {
                        DEBUG(0,("fetch_ldap_pw: neither ldap secret retrieved!\n"));
                        SAFE_FREE(old_style_key);
+                       SAFE_FREE(*pw);
                        SAFE_FREE(*dn);
                        SAFE_FREE(data);
                        return False;
@@ -375,6 +378,7 @@ bool fetch_ldap_pw(char **dn, char** pw)
                if (!secrets_store_ldap_pw(*dn, old_style_pw)) {
                        DEBUG(0,("fetch_ldap_pw: ldap secret could not be upgraded!\n"));
                        SAFE_FREE(old_style_key);
+                       SAFE_FREE(*pw);
                        SAFE_FREE(*dn);
                        return False;
                }