On 2023/8/14 14:43, Gao Xiang wrote:


On 2023/8/14 11:42, Jingbo Xu wrote:
Keep self allocated and maintained devname in erofs_sb_info.

Signed-off-by: Jingbo Xu <[email protected]>
---

...


@@ -95,7 +97,11 @@ int dev_open(struct erofs_sb_info *sbi, const char *dev)
          return -EINVAL;
      }
-    sbi->devname = dev;
+    sbi->devname = strdup(dev);

Could we move sbi->devname assignment to the beginning of the function?
e.g.

     ..
         sbi->devname = strdup(dev);
         if (!sbi->devname)
                 return -ENOMEM;

         fd = open(dev, O_RDWR | O_CREAT | O_BINARY, 0644);
     ...


+    if (!sbi->devname) {
+        close(fd);
+        return -ENOMEM;
+    }

After a second thought, since there are already several `close(fd);` in the
error paths and they are unavoidable.  So it looks good to me now:

Reviewed-by: Gao Xiang <[email protected]>

Thanks,
Gao Xiang

Reply via email to