Author: jra
Date: 2007-09-08 05:18:08 +0000 (Sat, 08 Sep 2007)
New Revision: 25022

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25022

Log:
Fix coverity #395. Resource leak on error.
Jeremy.

Modified:
   branches/SAMBA_3_2/source/nsswitch/wins.c
   branches/SAMBA_3_2_0/source/nsswitch/wins.c


Changeset:
Modified: branches/SAMBA_3_2/source/nsswitch/wins.c
===================================================================
--- branches/SAMBA_3_2/source/nsswitch/wins.c   2007-09-08 05:12:17 UTC (rev 
25021)
+++ branches/SAMBA_3_2/source/nsswitch/wins.c   2007-09-08 05:18:08 UTC (rev 
25022)
@@ -315,8 +315,10 @@
 
        namelen = strlen(name) + 1;
 
-       if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL)
+       if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL) {
+               free(ip_list);
                return NSS_STATUS_TRYAGAIN;
+       }
 
        memcpy(he->h_name, name, namelen);
 
@@ -325,24 +327,29 @@
        if ((i = (unsigned long)(buffer) % sizeof(char*)) != 0)
                i = sizeof(char*) - i;
 
-       if (get_static(&buffer, &buflen, i) == NULL)
+       if (get_static(&buffer, &buflen, i) == NULL) {
+               free(ip_list);
                return NSS_STATUS_TRYAGAIN;
+       }
 
        if ((he->h_addr_list = (char **)get_static(
-                    &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL)
+                    &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL) {
+               free(ip_list);
                return NSS_STATUS_TRYAGAIN;
+       }
 
        for (i = 0; i < count; i++) {
                if ((he->h_addr_list[i] = get_static(&buffer, &buflen,
-                                                    INADDRSZ)) == NULL)
+                                                    INADDRSZ)) == NULL) {
+                       free(ip_list);
                        return NSS_STATUS_TRYAGAIN;
+               }
                memcpy(he->h_addr_list[i], &ip_list[i], INADDRSZ);
        }
 
        he->h_addr_list[count] = NULL;
 
-       if (ip_list)
-               free(ip_list);
+       free(ip_list);
 
        /* Set h_addr_type and h_length */
 

Modified: branches/SAMBA_3_2_0/source/nsswitch/wins.c
===================================================================
--- branches/SAMBA_3_2_0/source/nsswitch/wins.c 2007-09-08 05:12:17 UTC (rev 
25021)
+++ branches/SAMBA_3_2_0/source/nsswitch/wins.c 2007-09-08 05:18:08 UTC (rev 
25022)
@@ -315,8 +315,10 @@
 
        namelen = strlen(name) + 1;
 
-       if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL)
+       if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL) {
+               free(ip_list);
                return NSS_STATUS_TRYAGAIN;
+       }
 
        memcpy(he->h_name, name, namelen);
 
@@ -325,24 +327,29 @@
        if ((i = (unsigned long)(buffer) % sizeof(char*)) != 0)
                i = sizeof(char*) - i;
 
-       if (get_static(&buffer, &buflen, i) == NULL)
+       if (get_static(&buffer, &buflen, i) == NULL) {
+               free(ip_list);
                return NSS_STATUS_TRYAGAIN;
+       }
 
        if ((he->h_addr_list = (char **)get_static(
-                    &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL)
+                    &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL) {
+               free(ip_list);
                return NSS_STATUS_TRYAGAIN;
+       }
 
        for (i = 0; i < count; i++) {
                if ((he->h_addr_list[i] = get_static(&buffer, &buflen,
-                                                    INADDRSZ)) == NULL)
+                                                    INADDRSZ)) == NULL) {
+                       free(ip_list);
                        return NSS_STATUS_TRYAGAIN;
+               }
                memcpy(he->h_addr_list[i], &ip_list[i], INADDRSZ);
        }
 
        he->h_addr_list[count] = NULL;
 
-       if (ip_list)
-               free(ip_list);
+       free(ip_list);
 
        /* Set h_addr_type and h_length */
 

Reply via email to