As a general rule, libraries should not emit any error messages.  A
library should depend on its consumer to present errors to users.

Remove log messages for memory allocation failures.

Signed-off-by: Chuck Lever <[email protected]>
---
 src/libnsdb/administrator.c |   27 +++++++----------------
 src/libnsdb/annotation.c    |   17 +++-----------
 src/libnsdb/connsec.c       |    4 +--
 src/libnsdb/fileserver.c    |   33 ++++++----------------------
 src/libnsdb/ldap.c          |   10 ++------
 src/libnsdb/nsdb.c          |   22 +++----------------
 src/libnsdb/path.c          |   51 ++++++++-----------------------------------
 7 files changed, 34 insertions(+), 130 deletions(-)

diff --git a/src/libnsdb/administrator.c b/src/libnsdb/administrator.c
index 29a7a92..862cd38 100644
--- a/src/libnsdb/administrator.c
+++ b/src/libnsdb/administrator.c
@@ -184,10 +184,9 @@ nsdb_construct_fsn_dn(const char *nce, const char 
*fsn_uuid)
        dn_len = strlen("fedfsFsnUuid=") + strlen(fsn_uuid) +
                                strlen(",") + strlen(nce) + 1;
        dn = ber_memalloc(dn_len);
-       if (dn == NULL) {
-               xlog(D_GENERAL, "%s: No memory for DN", __func__);
+       if (dn == NULL)
                return NULL;
-       }
+
        len = snprintf(dn, dn_len, "fedfsFsnUuid=%s,%s", fsn_uuid, nce);
        if (len < 0 || (size_t)len > dn_len) {
                xlog(D_GENERAL, "%s: DN is too long", __func__);
@@ -579,10 +578,9 @@ nsdb_construct_fsl_dn(const char *nce, const char 
*fsn_uuid, const char *fsl_uui
                strlen("fedfsFsnUuid=") + strlen(fsn_uuid) + strlen(",") +
                strlen(nce) + 1;
        dn = ber_memalloc(dn_len);
-       if (dn == NULL) {
-               xlog(D_GENERAL, "%s: No memory for FSL DN", __func__);
+       if (dn == NULL)
                return NULL;
-       }
+
        len = snprintf(dn, dn_len, "fedfsFslUuid=%s,fedfsFsnUuid=%s,%s",
                                fsl_uuid, fsn_uuid, nce);
        if (len < 0 || (size_t)len > dn_len) {
@@ -652,10 +650,8 @@ nsdb_construct_nfsuri(const struct fedfs_nfs_fsl *nfsfsl, 
char **nfsuri)
        len++;
 
        result = (char *)calloc(len, sizeof(char));
-       if (result == NULL) {
-               xlog(D_GENERAL, "%s calloc failed", __func__);
+       if (result == NULL)
                goto out;
-       }
 
        err = uriToStringA(result, &uri, len, NULL);
        if (err != URI_SUCCESS) {
@@ -1229,10 +1225,8 @@ nsdb_create_nce_add_top_entry(nsdb_t host, char **dn)
 
        len = strlen("o=fedfs");
        nce = ber_memalloc(len);
-       if (nce == NULL) {
-               xlog(D_GENERAL, "%s: No memory for NCE DN", __func__);
+       if (nce == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
        (void)sprintf(nce, "o=fedfs");
 
        xlog(D_CALL, "%s: Using DN '%s'", __func__, nce);
@@ -1297,10 +1291,8 @@ nsdb_create_nce_add_entry(nsdb_t host, const char 
*parent, char **dn)
 
        len = strlen("ou=fedfs,") + strlen(parent) + 1;
        nce = ber_memalloc(len);
-       if (nce == NULL) {
-               xlog(D_GENERAL, "%s: No memory for NCE DN", __func__);
+       if (nce == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
        (void)sprintf(nce, "ou=fedfs,%s", parent);
 
        xlog(D_CALL, "%s: Using DN '%s'", __func__, nce);
@@ -1356,11 +1348,8 @@ nsdb_create_simple_nce_s(nsdb_t host, const char 
*parent, char **dn)
        retval = FEDFS_OK;
        if (dn != NULL) {
                *dn = strdup(nce);
-               if (*dn == NULL) {
-                       xlog(D_GENERAL, "%s: No memory for DN",
-                               __func__);
+               if (*dn == NULL)
                        retval = FEDFS_ERR_SVRFAULT;
-               }
        }
        ber_memfree(nce);
        return retval;
diff --git a/src/libnsdb/annotation.c b/src/libnsdb/annotation.c
index 6444122..8ad759b 100644
--- a/src/libnsdb/annotation.c
+++ b/src/libnsdb/annotation.c
@@ -115,11 +115,8 @@ nsdb_sanitize_annotation(const char *in, char **out)
        /* Assume worst case: every input character must be escaped */
        len = strlen(in);
        result = malloc(len * 2 + 1);
-       if (result == NULL) {
-               xlog(D_GENERAL, "%s: Failed to allocate output buffer",
-                       __func__);
+       if (result == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0, j = 0; i < len; i++) {
                /* escape as needed */
@@ -162,11 +159,8 @@ nsdb_construct_annotation(const char *keyword, const char 
*value,
        /* Assume worst case: every input character must be escaped */
        buf = malloc(strlen(keyword) * 2 + strlen(value) * 2 +
                        strlen("\"\" = \"\""));
-       if (buf == NULL) {
-               xlog(D_GENERAL, "%s: Failed to allocate output buffer",
-                       __func__);
+       if (buf == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        buf[0] = '\0';
        strcat(buf, "\"");
@@ -317,15 +311,10 @@ nsdb_parse_annotation(const char *annotation, size_t len,
 
        /* Made up value that will always be large enough */
        tmpkey = calloc(1, len);
-       if (tmpkey == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate buffer for KEY",
-                       __func__);
+       if (tmpkey == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
        tmpval = calloc(1, len);
        if (tmpval == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate buffer for KEY",
-                       __func__);
                free(tmpkey);
                return FEDFS_ERR_SVRFAULT;
        }
diff --git a/src/libnsdb/connsec.c b/src/libnsdb/connsec.c
index 4b68c61..bb81eee 100644
--- a/src/libnsdb/connsec.c
+++ b/src/libnsdb/connsec.c
@@ -169,10 +169,8 @@ nsdb_connsec_read_bio_x509(const char *certfile, BIO *bio,
                return retval;
 
        buf = (unsigned char *)calloc(1, size);
-       if (buf == NULL) {
-               xlog(D_GENERAL, "%s: failed to allocate buffer", __func__);
+       if (buf == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        retval = nsdb_connsec_read_bio_x509_buf(certfile, bio, buf);
        if (retval != FEDFS_OK) {
diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c
index 7c96c4e..d1bb71a 100644
--- a/src/libnsdb/fileserver.c
+++ b/src/libnsdb/fileserver.c
@@ -314,7 +314,6 @@ nsdb_parse_ncedn_attribute(LDAP *ld, LDAPMessage *entry, 
char *attr,
 
        tmp = strdup(values[0]->bv_val);
        if (tmp == NULL) {
-               xlog(L_ERROR, "%s: strdup(3) failed for %s", __func__, attr);
                retval = FEDFS_ERR_SVRFAULT;
                goto out_free;
        }
@@ -480,11 +479,8 @@ nsdb_parse_ncedn(LDAP *ld, LDAPMessage *entry, char **dn)
        }
 
        *dn = strdup(tmp);
-       if (*dn == NULL) {
-               xlog(D_GENERAL, "%s: strdup failed",
-                       __func__);
+       if (*dn == NULL)
                goto out;
-       }
 
        retval = FEDFS_OK;
 
@@ -838,17 +834,12 @@ nsdb_parse_annotations(struct berval **values, char 
***annotations)
 
        count = ldap_count_values_len(values);
        tmp_annos = calloc(count + 1, sizeof(char *));
-       if (tmp_annos == NULL) {
-               xlog(D_GENERAL, "%s: no memory for annotations array",
-                       __func__);
+       if (tmp_annos == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0; i < count; i++) {
                tmp_annos[i] = strndup(values[i]->bv_val, values[i]->bv_len);
                if (tmp_annos[i] == NULL) {
-                       xlog(D_GENERAL, "%s: no memory for annotation",
-                               __func__);
                        nsdb_free_string_array(tmp_annos);
                        return FEDFS_ERR_SVRFAULT;
                }
@@ -1111,10 +1102,8 @@ nsdb_resolve_fsn_parse_entry(LDAP *ld, LDAPMessage 
*entry,
        xlog(D_CALL, "%s: parsing entry", __func__);
 
        new = nsdb_alloc_fedfs_fsl();
-       if (new == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate new fsl", __func__);
+       if (new == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        dn = ldap_get_dn(ld, entry);
        if (dn != NULL ) {
@@ -1174,10 +1163,8 @@ nsdb_resolve_fsn_find_entry_s(nsdb_t host, const char 
*nce, const char *fsn_uuid
        char *filter;
 
        filter = malloc(128);
-       if (filter == NULL) {
-               xlog(D_GENERAL, "%s: failed to allocate buffer", __func__);
+       if (filter == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        len = snprintf(filter, 127,
                        "(&(objectClass=fedfsFsl)(fedfsFsnUuid=%s))", fsn_uuid);
@@ -1424,10 +1411,8 @@ nsdb_get_fsn_parse_entry(LDAP *ld, LDAPMessage *entry,
        xlog(D_CALL, "%s: parsing entry", __func__);
 
        new = nsdb_alloc_fedfs_fsn();
-       if (new == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate new fsn", __func__);
+       if (new == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        dn = ldap_get_dn(ld, entry);
        if (dn != NULL ) {
@@ -1488,10 +1473,8 @@ nsdb_get_fsn_find_entry_s(nsdb_t host, const char *nce, 
const char *fsn_uuid,
        char *filter;
 
        filter = malloc(128);
-       if (filter == NULL) {
-               xlog(D_GENERAL, "%s: failed to allocate buffer", __func__);
+       if (filter == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        len = snprintf(filter, 127,
                        "(&(objectClass=fedfsFsn)(fedfsFsnUuid=%s))", fsn_uuid);
@@ -2017,10 +2000,8 @@ nsdb_match_root_suffix(const char *entry, char 
**contexts,
 
 found:
        *context = strdup(contexts[i]);
-       if (*context == NULL) {
-               xlog(D_GENERAL, "%s: No memory", __func__);
+       if (*context == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        xlog(D_CALL, "%s: context='%s'", __func__, contexts[i]);
        return FEDFS_OK;
diff --git a/src/libnsdb/ldap.c b/src/libnsdb/ldap.c
index 84a641c..03abeda 100644
--- a/src/libnsdb/ldap.c
+++ b/src/libnsdb/ldap.c
@@ -427,15 +427,12 @@ nsdb_parse_multivalue_str(char *attr, struct berval 
**values, char ***result)
 
        count = ldap_count_values_len(values);
        tmp = calloc(count + 1, sizeof(char *));
-       if (tmp == NULL) {
-               xlog(D_GENERAL, "%s: no memory for array", __func__);
+       if (tmp == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0; i < count; i++) {
                tmp[i] = strdup(values[i]->bv_val);
                if (tmp[i] == NULL) {
-                       xlog(D_GENERAL, "%s: no memory for string", __func__);
                        nsdb_free_string_array(tmp);
                        return FEDFS_ERR_SVRFAULT;
                }
@@ -817,15 +814,12 @@ nsdb_copy_referrals_array(char **refs, char ***referrals)
        count = i;
 
        tmp = calloc(count, sizeof(char *));
-       if (tmp == NULL) {
-               xlog(D_GENERAL, "%s: no memory for array", __func__);
+       if (tmp == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0; i < count; i++) {
                tmp[i] = strdup(refs[i]);
                if (tmp[i] == NULL) {
-                       xlog(D_GENERAL, "%s: no memory for string", __func__);
                        nsdb_free_string_array(tmp);
                        return FEDFS_ERR_SVRFAULT;
                }
diff --git a/src/libnsdb/nsdb.c b/src/libnsdb/nsdb.c
index 7320b05..d24df29 100644
--- a/src/libnsdb/nsdb.c
+++ b/src/libnsdb/nsdb.c
@@ -197,11 +197,8 @@ nsdb_create_private_certfile(char **pathbuf)
        }
 
        tmp = malloc(PATH_MAX);
-       if (tmp == NULL) {
-               xlog(D_GENERAL, "%s: failed to allocate pathname buffer",
-                       __func__);
+       if (tmp == NULL)
                goto out;
-       }
 
        len = snprintf(tmp, PATH_MAX, "%s/nsdbXXXXXX.pem",
                                fedfs_nsdbcerts_dirname);
@@ -564,17 +561,12 @@ nsdb_new_nsdb(const char *hostname, const unsigned long 
port, nsdb_t *host)
                port_tmp = port;
 
        hostname_tmp = strdup(hostname);
-       if (hostname_tmp == NULL) {
-               xlog(D_GENERAL, "%s: Failed to allocate memory for nsdb object",
-                               __func__);
+       if (hostname_tmp == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        *host = malloc(sizeof(**host));
        if (*host == NULL) {
                free(hostname_tmp);
-               xlog(D_GENERAL, "%s: Failed to allocate memory for nsdb object",
-                               __func__);
                return FEDFS_ERR_SVRFAULT;
        }
 
@@ -1441,11 +1433,8 @@ nsdb_enumerate_nsdbs(char ***nsdblist)
        }
 
        result = calloc(nrows + 1, sizeof(char *));
-       if (result == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate memory for result",
-                       __func__);
+       if (result == NULL)
                goto out_free;
-       }
 
        for (i = 0; i < nrows; i++) {
                char *hostname = resultp[(i + 1) * 2];
@@ -1453,12 +1442,9 @@ nsdb_enumerate_nsdbs(char ***nsdblist)
                char *tmp;
 
                tmp = malloc(strlen(hostname) + strlen(":") + strlen(port) + 1);
-               if (tmp == NULL) {
-                       xlog(L_ERROR, "%s: Failed to allocate memory "
-                               "for result", __func__);
+               if (tmp == NULL)
                        nsdb_free_string_array(result);
                        goto out_free;
-               }
 
                (void)sprintf(tmp, "%s:%s", hostname, port);
 
diff --git a/src/libnsdb/path.c b/src/libnsdb/path.c
index a7cb524..bc4d804 100644
--- a/src/libnsdb/path.c
+++ b/src/libnsdb/path.c
@@ -88,11 +88,8 @@ nsdb_alloc_zero_component_pathname(char ***path_array)
        xlog(D_GENERAL, "%s: Zero-component pathname", __func__);
 
        result = (char **)calloc(1, sizeof(char *));
-       if (result == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate array",
-                       __func__);
+       if (result == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
        result[0] = NULL;
        *path_array = result;
        return FEDFS_OK;
@@ -122,11 +119,8 @@ nsdb_normalize_path(const char *pathname)
        }
 
        result = malloc(len + 1);
-       if (result == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate pathname buffer",
-                       __func__);
+       if (result == NULL)
                return NULL;
-       }
 
        for (i = 0, j = 0; i < len; i++) {
                if (pathname[i] == '/' && pathname[i + 1] == '/')
@@ -160,11 +154,8 @@ nsdb_count_components(const char *pathname, size_t *len,
 
        /* strtok(3) will tromp on the string */
        start = strdup(pathname);
-       if (start == NULL) {
-               xlog(L_ERROR, "%s: Failed to duplicate pathname",
-                       __func__);
+       if (start == NULL)
                return false;
-       }
 
        length = XDR_UINT_BYTES;
        count = 0;
@@ -279,11 +270,8 @@ nsdb_path_array_to_posix(char * const *path_array, char 
**pathname)
        if (path_array[0] == NULL) {
                xlog(D_GENERAL, "%s: Zero-component pathname", __func__);
                result = strdup("/");
-               if (result == NULL) {
-                       xlog(D_GENERAL, "%s: Failed to allocate buffer for 
result",
-                               __func__);
+               if (result == NULL)
                        return FEDFS_ERR_SVRFAULT;
-               }
                *pathname = result;
                return FEDFS_OK;
        }
@@ -322,11 +310,8 @@ nsdb_path_array_to_posix(char * const *path_array, char 
**pathname)
        }
 
        result = calloc(1, length + 1);
-       if (result == NULL) {
-               xlog(D_GENERAL, "%s: Failed to allocate buffer for result",
-                       __func__);
+       if (result == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0; i < count; i++) {
                strcat(result, "/");
@@ -378,11 +363,8 @@ nsdb_posix_to_path_array(const char *pathname, char 
***path_array)
        }
 
        result = (char **)calloc(count + 1, sizeof(char *));
-       if (result == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate array",
-                       __func__);
+       if (result == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        component = normalized;
        for (i = 0; ; i++) {
@@ -396,12 +378,9 @@ nsdb_posix_to_path_array(const char *pathname, char 
***path_array)
                length = next - component;
 
                result[i] = strndup(component, length);
-               if (result[i] == NULL) {
-                       xlog(D_GENERAL, "%s: Failed to allocate "
-                                       "new pathname component", __func__);
+               if (result[i] == NULL)
                        nsdb_free_string_array(result);
                        return FEDFS_ERR_SVRFAULT;
-               }
 
                if (*next == '\0')
                        break;
@@ -485,8 +464,6 @@ nsdb_path_array_to_fedfspathname(char * const *path_array, 
FedFsPathName *fpath)
 
                if (!nsdb_new_component(component, len,
                                        &fpath->FedFsPathName_val[i])) {
-                       xlog(D_GENERAL, "%s: Failed to allocate "
-                                       "new pathname component", __func__);
                        nsdb_free_fedfspathname(fpath);
                        return FEDFS_ERR_SVRFAULT;
                }
@@ -557,11 +534,8 @@ nsdb_fedfspathname_to_path_array(FedFsPathName fpath, char 
***path_array)
        }
 
        result = (char **)calloc(fpath.FedFsPathName_len + 1, sizeof(char *));
-       if (result == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate array",
-                       __func__);
+       if (result == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0; i < fpath.FedFsPathName_len; i++) {
                fcomp = fpath.FedFsPathName_val[i];
@@ -570,8 +544,6 @@ nsdb_fedfspathname_to_path_array(FedFsPathName fpath, char 
***path_array)
 
                result[i] = strndup(component, (size_t)len);
                if (result[i] == NULL) {
-                       xlog(D_GENERAL, "%s: Failed to allocate "
-                                       "new pathname component", __func__);
                        nsdb_free_string_array(result);
                        return FEDFS_ERR_SVRFAULT;
                }
@@ -776,11 +748,8 @@ nsdb_uri_pathname_to_path_array(const UriUriA *uri, char 
***path_array)
                return nsdb_alloc_zero_component_pathname(path_array);
 
        result = (char **)calloc(count + 1, sizeof(char *));
-       if (result == NULL) {
-               xlog(L_ERROR, "%s: Failed to allocate array",
-                       __func__);
+       if (result == NULL)
                return FEDFS_ERR_SVRFAULT;
-       }
 
        for (i = 0; pos != NULL; pos = pos->next) {
                size_t len;
@@ -798,8 +767,6 @@ nsdb_uri_pathname_to_path_array(const UriUriA *uri, char 
***path_array)
                result[i] = strndup((char *)pos->text.first, len);
                if (result[i] == NULL) {
                        nsdb_free_string_array(result);
-                       xlog(L_ERROR, "%s: Failed to allocate component string",
-                               __func__);
                        return FEDFS_ERR_SVRFAULT;
                }
                i++;


_______________________________________________
fedfs-utils-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/fedfs-utils-devel

Reply via email to