Merge remote-tracking branch 'origin/fastpath'

* origin/fastpath:
  Small raw reader fixes * crash when accessing nonexistant file. * memory leak when reading from file.
This commit is contained in:
Robin Sommer 2013-07-15 18:18:20 -07:00
commit 18201afcf8
3 changed files with 22 additions and 9 deletions

View file

@ -1,4 +1,10 @@
2.1-814 | 2013-07-15 18:18:20 -0700
* Fixing raw reader crash when accessing nonexistant file, and
memory leak when reading from file. Addresses #1038. (Bernhard
Amann)
2.1-811 | 2013-07-14 08:01:54 -0700
* Bump sqlite to 3.7.17. (Bernhard Amann)

View file

@ -1 +1 @@
2.1-811
2.1-814

View file

@ -55,6 +55,13 @@ void Raw::DoClose()
if ( file != 0 )
CloseInput();
if ( buf != 0 )
{
// we still have output that has not been flushed. Throw away.
delete buf;
buf = 0;
}
if ( execute && childpid > 0 && kill(childpid, 0) == 0 )
{
// kill child process
@ -157,13 +164,13 @@ bool Raw::OpenInput()
else
{
file = fopen(fname.c_str(), "r");
fcntl(fileno(file), F_SETFD, FD_CLOEXEC);
if ( ! file )
{
Error(Fmt("Init: cannot open %s", fname.c_str()));
return false;
}
}
fcntl(fileno(file), F_SETFD, FD_CLOEXEC);
return true;
}
@ -322,13 +329,15 @@ int64_t Raw::GetLine(FILE* arg_file)
// but first check if we encountered the file end - because if we did this was it.
if ( feof(arg_file) != 0 )
{
outbuf = buf;
buf = 0;
if ( pos == 0 )
return -1; // signal EOF - and that we had no more data.
else
{
outbuf = buf;
buf = 0;
return pos;
}
}
repeats++;
// bah, we cannot use realloc because we would have to change the delete in the manager to a free.
@ -342,8 +351,6 @@ int64_t Raw::GetLine(FILE* arg_file)
{
outbuf = buf;
buf = 0;
buf = new char[block_size];
if ( found < pos )
{
@ -368,7 +375,7 @@ int64_t Raw::GetLine(FILE* arg_file)
return -3;
}
InternalError("Internal control flow execution");
InternalError("Internal control flow execution error in raw reader");
assert(false);
}