* CID 1012: Fix leaking the OffsetFile in case it fails to initialize.
* Use std::nothrow (the rest of the file already used it). * We also have to keep the source file around and properly dispose it, as OffsetFile doesn't take ownership of it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27486 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -754,6 +754,7 @@ const static void *kTableEntries[] = {
|
|||||||
ServerPicture::ServerPicture()
|
ServerPicture::ServerPicture()
|
||||||
:
|
:
|
||||||
PictureDataWriter(),
|
PictureDataWriter(),
|
||||||
|
fFile(NULL),
|
||||||
fData(NULL),
|
fData(NULL),
|
||||||
fPictures(NULL),
|
fPictures(NULL),
|
||||||
fUsurped(NULL)
|
fUsurped(NULL)
|
||||||
@@ -768,6 +769,7 @@ ServerPicture::ServerPicture()
|
|||||||
ServerPicture::ServerPicture(const ServerPicture &picture)
|
ServerPicture::ServerPicture(const ServerPicture &picture)
|
||||||
:
|
:
|
||||||
PictureDataWriter(),
|
PictureDataWriter(),
|
||||||
|
fFile(NULL),
|
||||||
fData(NULL),
|
fData(NULL),
|
||||||
fPictures(NULL),
|
fPictures(NULL),
|
||||||
fUsurped(NULL)
|
fUsurped(NULL)
|
||||||
@@ -793,19 +795,25 @@ ServerPicture::ServerPicture(const ServerPicture &picture)
|
|||||||
ServerPicture::ServerPicture(const char *fileName, const int32 &offset)
|
ServerPicture::ServerPicture(const char *fileName, const int32 &offset)
|
||||||
:
|
:
|
||||||
PictureDataWriter(),
|
PictureDataWriter(),
|
||||||
|
fFile(NULL),
|
||||||
fData(NULL),
|
fData(NULL),
|
||||||
fPictures(NULL),
|
fPictures(NULL),
|
||||||
fUsurped(NULL)
|
fUsurped(NULL)
|
||||||
{
|
{
|
||||||
BPrivate::Storage::OffsetFile *file =
|
fFile = new (std::nothrow) BFile(fileName, B_READ_WRITE);
|
||||||
new BPrivate::Storage::OffsetFile(new BFile(fileName, B_READ_WRITE), (off_t)offset);
|
if (fFile == NULL)
|
||||||
|
|
||||||
if (file == NULL || file->InitCheck() != B_OK)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fData = file;
|
BPrivate::Storage::OffsetFile *offsetFile =
|
||||||
|
new (std::nothrow) BPrivate::Storage::OffsetFile(fFile, (off_t)offset);
|
||||||
|
if (offsetFile == NULL || offsetFile->InitCheck() != B_OK) {
|
||||||
|
delete offsetFile;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fData = offsetFile;
|
||||||
fToken = gTokenSpace.NewToken(kPictureToken, this);
|
fToken = gTokenSpace.NewToken(kPictureToken, this);
|
||||||
|
|
||||||
PictureDataWriter::SetTo(fData);
|
PictureDataWriter::SetTo(fData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,6 +821,7 @@ ServerPicture::ServerPicture(const char *fileName, const int32 &offset)
|
|||||||
ServerPicture::~ServerPicture()
|
ServerPicture::~ServerPicture()
|
||||||
{
|
{
|
||||||
delete fData;
|
delete fData;
|
||||||
|
delete fFile;
|
||||||
gTokenSpace.RemoveToken(fToken);
|
gTokenSpace.RemoveToken(fToken);
|
||||||
|
|
||||||
// We only delete the subpictures list, not the subpictures themselves,
|
// We only delete the subpictures list, not the subpictures themselves,
|
||||||
@@ -1044,5 +1053,3 @@ ServerPicture::ExportData(BPrivate::PortLink &link)
|
|||||||
fData->Seek(oldPosition, SEEK_SET);
|
fData->Seek(oldPosition, SEEK_SET);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
class ServerApp;
|
class ServerApp;
|
||||||
class View;
|
class View;
|
||||||
|
class BFile;
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
class LinkReceiver;
|
class LinkReceiver;
|
||||||
class PortLink;
|
class PortLink;
|
||||||
@@ -53,6 +55,7 @@ friend class ServerApp;
|
|||||||
~ServerPicture();
|
~ServerPicture();
|
||||||
|
|
||||||
int32 fToken;
|
int32 fToken;
|
||||||
|
BFile *fFile;
|
||||||
BPositionIO *fData;
|
BPositionIO *fData;
|
||||||
// DrawState *fState;
|
// DrawState *fState;
|
||||||
BList *fPictures;
|
BList *fPictures;
|
||||||
|
|||||||
Reference in New Issue
Block a user