Whamcloud - gitweb
LU-1884 build: fix 'resource leak' errors
[fs/lustre-release.git] / lustre / utils / lustre_rsync.c
index 43fa7b4..85c8a1f 100644 (file)
@@ -1386,7 +1386,7 @@ int lr_replicate()
 {
         void *changelog_priv;
         struct lr_info *info;
-        struct lr_info *ext;
+       struct lr_info *ext = NULL;
         time_t start;
         int xattr_not_supp;
         int i;
@@ -1402,15 +1402,17 @@ int lr_replicate()
         if (rc) {
                 fprintf(stderr, "Source path is not a valid Lustre client "
                         "mountpoint.\n");
-                return rc;
+               goto out;
         }
         if (status->ls_mdt_device[0] == '\0')
                 snprintf(status->ls_mdt_device, LR_NAME_MAXLEN, "%s%s",
                         status->ls_source_fs, DEFAULT_MDT);
 
         ext = calloc(1, sizeof(struct lr_info));
-        if (ext == NULL)
-                return -ENOMEM;
+       if (ext == NULL) {
+               rc = -ENOMEM;
+               goto out;
+       }
 
         for (i = 0, xattr_not_supp = 0; i < status->ls_num_targets; i++) {
                 snprintf(info->dest, PATH_MAX, "%s/%s", status->ls_targets[i],
@@ -1419,7 +1421,8 @@ int lr_replicate()
                 if (rc == -1 && errno != EEXIST) {
                         fprintf(stderr, "Error writing to target path %s.\n",
                                 status->ls_targets[i]);
-                        return -errno;
+                       rc = -errno;
+                       goto out;
                 }
                 rc = llistxattr(info->src, info->xlist, info->xsize);
                 if (rc == -1 && errno == ENOTSUP) {
@@ -1440,7 +1443,7 @@ int lr_replicate()
         if (rc < 0) {
                 fprintf(stderr, "Error opening changelog file for fs %s.\n",
                         status->ls_source_fs);
-                return rc;
+               goto out;
         }
 
         while (!quit && lr_parse_line(changelog_priv, info) == 0) {
@@ -1523,7 +1526,15 @@ int lr_replicate()
                 printf("Changelog records consumed: %lld\n", rec_count);
         }
 
-        return 0;
+       rc = 0;
+
+out:
+       if (info != NULL)
+               free(info);
+       if (ext != NULL)
+               free(ext);
+
+       return rc;
 }
 
 void