csa/match.c: coverity CID 87204; bad free; WTF
authorJon Trulson <jon@radscan.com>
Sun, 1 Apr 2018 00:36:22 +0000 (18:36 -0600)
committerJon Trulson <jon@radscan.com>
Sun, 1 Apr 2018 00:36:22 +0000 (18:36 -0600)
cde/lib/csa/match.c

index eb8947f53ed7fec4ee747017863e7ffda98f2818..a740ce10b1e919a40a3fcac80b2a89d234ef5bd4 100644 (file)
@@ -220,6 +220,7 @@ _DtCmHashCriteria(
                }
 
                if (keep == B_TRUE) {
+                        void *savedHattrs = NULL;
                        if (*hattrs == NULL) {
                                if ((*hattrs = (cms_attribute *)calloc(1,
                                    sizeof(cms_attribute)*(num_attrs-i)+
@@ -231,14 +232,15 @@ _DtCmHashCriteria(
                                        free(*hattrs);
                                        return (CSA_E_INSUFFICIENT_MEMORY);
                                } else {
+                                        savedHattrs = (void *)*hattrs;
                                        *((char**)(*hattrs)) = (char *)&hval[0];
                                        *hattrs = (cms_attribute *)\
                                                ((char *)(*hattrs)+sizeof(char*));
                                }
                                if (ops && (*hops = (CSA_enum *)calloc(1,
                                    sizeof(CSA_enum)*(num_attrs-i))) == NULL) {
-                                       free(*hattrs);
                                        free(hval);
+                                       free(savedHattrs);
                                        return (CSA_E_INSUFFICIENT_MEMORY);
                                }
                        }