don't set variable we don't use
authorChristos Zoulas <christos@zoulas.com>
Thu, 6 Oct 2011 14:40:14 +0000 (10:40 -0400)
committerChristos Zoulas <christos@zoulas.com>
Thu, 6 Oct 2011 14:40:14 +0000 (10:40 -0400)
don't check for NULL before XFREE
strdup -> xstrdup

amd/sun_map.c

index 0d1181f438bbeaa19ae2da7bb59a91c8c914997a..68096364d680e0982c0494ee01ddb4323dd242de 100644 (file)
@@ -167,7 +167,7 @@ sun_strsub(const char *src, const char *str, const char *sub)
   (void)strncat(retval, sub, sub_size);
   (void)strncat(retval, str_end + 1, second_half);
 
-  if ((str_start = strstr(retval, str)) != NULL) {
+  if (strstr(retval, str) != NULL) {
     /*
      * If there is another occurrences of str call this function
      * recursively.
@@ -206,7 +206,7 @@ sun_expand2amd(const char *str)
    * each of the replace attempt will fail and we'll move on to the
    * next char.
    */
-  tmp = strdup(str);
+  tmp = xstrdup(str);
   for (pos = str; *pos != '\0'; pos++) {
     if (*pos != '$') {
       continue;
@@ -258,9 +258,7 @@ sun_expand2amd(const char *str)
   }
   else {
     retval = tmp2;
-    if (tmp != NULL) {
-      XFREE(tmp);
-    }
+    XFREE(tmp);
   }
 
   return retval;
@@ -311,19 +309,15 @@ sun_append_str(char *dest,
    * Try to convert any variable substitutions. If this function
    * returns a new string one or more var subs where expanded.
    */
-  else if ((sub = sun_expand2amd(out)) != NULL) {
+  else if (out != NULL && (sub = sun_expand2amd(out)) != NULL) {
     out = sub;
   }
 
   if (out != NULL) {
     xstrlcat(dest, out, destlen);
   }
-  if (sub != NULL) {
-    XFREE(sub);
-  }
-  if (sub2 != NULL) {
-    XFREE(sub2);
-  }
+  XFREE(sub);
+  XFREE(sub2);
 }
 
 
@@ -555,7 +549,7 @@ sun_entry2amd(const char *key, const char *s_entry_str)
   if (s_entry->mountpt_list != NULL) {
     /* multi-mount point */
     sun_multi2amd(line_buff, sizeof(line_buff), key, s_entry);
-    retval = strdup(line_buff);
+    retval = xstrdup(line_buff);
   }
   else {
     /* single mount point */
@@ -563,12 +557,12 @@ sun_entry2amd(const char *key, const char *s_entry_str)
       if (NSTREQ(s_entry->fstype, SUN_NFS_TYPE, strlen(SUN_NFS_TYPE))) {
        /* NFS Type */
        sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
-       retval = strdup(line_buff);
+       retval = xstrdup(line_buff);
       }
       else if (NSTREQ(s_entry->fstype, SUN_HSFS_TYPE, strlen(SUN_HSFS_TYPE))) {
        /* HSFS Type (CD fs) */
        sun_hsfs2amd(line_buff, sizeof(line_buff), key, s_entry);
-       retval = strdup(line_buff);
+       retval = xstrdup(line_buff);
       }
       /*
        * XXX: The following fstypes are not yet supported.
@@ -595,13 +589,11 @@ sun_entry2amd(const char *key, const char *s_entry_str)
     else {
       plog(XLOG_INFO, "No SUN fstype specified defaulting to NFS.");
       sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
-      retval = strdup(line_buff);
+      retval = xstrdup(line_buff);
     }
   }
 
  err:
-  if (s_entry != NULL) {
-    XFREE(s_entry);
-  }
+  XFREE(s_entry);
   return retval;
 }