tools/dumpscan/pathname.c: properly check strdup() return value
[openafs.git] / src / tools / dumpscan / pathname.c
index 0057df8..b4d4e5c 100644 (file)
@@ -48,9 +48,8 @@ get_vhash_ent(path_hashinfo * phi, afs_uint32 vnode, int make)
     for (vhe = phi->hash_table[key]; vhe && vhe->vnode != vnode;
         vhe = vhe->next);
     if (make && !vhe) {
-       vhe = (vhash_ent *) malloc(sizeof(vhash_ent));
+       vhe = calloc(1, sizeof(vhash_ent));
        if (vhe) {
-           memset(vhe, 0, sizeof(vhash_ent));
            vhe->vnode = vnode;
            vhe->next = phi->hash_table[key];
            phi->hash_table[key] = vhe;
@@ -71,10 +70,9 @@ volhdr_cb(afs_vol_header * hdr, XFILE * X, void *refcon)
        for (phi->hash_size = 1; nfiles > BUCKET_SIZE;
             phi->hash_size++, nfiles >>= 1);
        hsize = (1 << phi->hash_size);
-       phi->hash_table = (vhash_ent **) malloc(hsize * sizeof(vhash_ent *));
+       phi->hash_table = calloc(hsize ,sizeof(vhash_ent *));
        if (!phi->hash_table)
            return ENOMEM;
-       memset(phi->hash_table, 0, hsize * sizeof(vhash_ent *));
        return 0;
     } else {
        if (phi->p->cb_error)
@@ -279,14 +277,13 @@ Path_Build(XFILE * X, path_hashinfo * phi, afs_uint32 vnode, char **his_path,
     int nl, pl = 0;
 
     if (vnode == 1) {
-       *his_path = (char *)malloc(2);
-       if (!his_path) {
+       *his_path = strdup("/");
+       if (!*his_path) {
            if (phi->p->cb_error)
                (phi->p->cb_error) (ENOMEM, 1, phi->p->err_refcon,
                                    "No memory for pathname of vnode 1");
            return ENOMEM;
        }
-       strcpy(*his_path, "/");
        return 0;
     }
 
@@ -365,7 +362,7 @@ Path_Build(XFILE * X, path_hashinfo * phi, afs_uint32 vnode, char **his_path,
 
        nl = strlen(name);
        if (path) {
-           path = (char *)realloc(path, nl + pl + 2);
+           path = realloc(path, nl + pl + 2);
            if (!path) {
                if (phi->p->cb_error)
                    (phi->p->cb_error) (ENOMEM, 1, phi->p->err_refcon,