> On Oct. 28, 2016, 1:03 a.m., Jie Yu wrote:
> > 3rdparty/stout/include/stout/os/posix/xattr.hpp, lines 71-72
> > <https://reviews.apache.org/r/53041/diff/4/?file=1544874#file1544874line71>
> >
> >     I think James made a valid point there that errno might not be 
> > preserved across delete. So using a vector<char> sounds better.

I think `delete` will not change `errno`, I verified it by a small program:
```
#include <errno.h>
#include <fcntl.h>

int main()
{
  char* temp = new char[4];

  if (open("/xxx", 0) < 0) {
    delete[] temp;
    return errno;
  }
 
  delete[] temp;
  return 0;
}
```
This program tries to open a file `/xxx` which does not exist, and when I run 
it, its exit code is 2 (i.e., `ENOENT`). And actually in stout I see there are 
also some other codes using `delete` and `ErrnoError` in the same way, e.g.:
https://github.com/apache/mesos/blob/1.0.1/3rdparty/stout/include/stout/os/mktemp.hpp#L40:L41
https://github.com/apache/mesos/blob/1.0.1/3rdparty/stout/include/stout/os/posix/mkdtemp.hpp#L37:L38

However, I do see there are also some codes which tries to avoid `delete` 
affecting `ErrnoError` in this way:
```
Error error = ErrnoError();
delete[] temp;
return error;
```
https://github.com/apache/mesos/blob/1.0.1/3rdparty/stout/include/stout/os/read.hpp#L67:L69
https://github.com/apache/mesos/blob/1.0.1/3rdparty/stout/include/stout/os/sysctl.hpp#L200:L202


So the codes in stout are inconsistent regarding this issue. I think we should 
fix it by making them handle this issue in a consistent way, I would prefer the 
following way:
```
Error error = ErrnoError();
delete[] temp;
return error;
```

Let me know your comments :-)


- Qian


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/53041/#review154042
-----------------------------------------------------------


On Oct. 25, 2016, 11:41 a.m., Qian Zhang wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/53041/
> -----------------------------------------------------------
> 
> (Updated Oct. 25, 2016, 11:41 a.m.)
> 
> 
> Review request for mesos and Jie Yu.
> 
> 
> Bugs: MESOS-6360
>     https://issues.apache.org/jira/browse/MESOS-6360
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> Added `setxattr()` and `getxattr()` in stout.
> 
> 
> Diffs
> -----
> 
>   3rdparty/stout/include/Makefile.am 1eb9c146d3eebacaea32e0f724d145f0c1dd676f 
>   3rdparty/stout/include/stout/os.hpp 
> 96e8621b198a3ec4cce78e0a6ff5f271eda05ff1 
>   3rdparty/stout/include/stout/os/posix/xattr.hpp PRE-CREATION 
>   3rdparty/stout/include/stout/os/windows/xattr.hpp PRE-CREATION 
>   3rdparty/stout/include/stout/os/xattr.hpp PRE-CREATION 
> 
> Diff: https://reviews.apache.org/r/53041/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Qian Zhang
> 
>

Reply via email to