Fixed various errors/warnings reported by cppcheck:

* memory leaks
* resource leaks
* added const's to getters
* removed a few reundant conditions


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35433 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Artur Wyszynski 2010-02-08 22:50:38 +00:00
parent c0cd8cf199
commit cee04e8074
54 changed files with 153 additions and 126 deletions

View File

@ -17,50 +17,50 @@ class BGLRenderer
{ {
// Private unimplemented copy constructors // Private unimplemented copy constructors
BGLRenderer(const BGLRenderer &); BGLRenderer(const BGLRenderer &);
BGLRenderer & operator=(const BGLRenderer &); BGLRenderer & operator=(const BGLRenderer &);
public: public:
BGLRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher); BGLRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher);
virtual ~BGLRenderer(); virtual ~BGLRenderer();
void Acquire(); void Acquire();
void Release(); void Release();
virtual void LockGL(); virtual void LockGL();
virtual void UnlockGL(); virtual void UnlockGL();
virtual void SwapBuffers(bool VSync = false); virtual void SwapBuffers(bool VSync = false);
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest); virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest);
virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest); virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest);
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
virtual void DirectConnected(direct_buffer_info *info); virtual void DirectConnected(direct_buffer_info *info);
virtual void EnableDirectMode(bool enabled); virtual void EnableDirectMode(bool enabled);
inline int32 ReferenceCount() { return fRefCount; }; inline int32 ReferenceCount() const { return fRefCount; };
inline ulong Options() { return fOptions; }; inline ulong Options() const { return fOptions; };
inline BGLView * GLView() { return fView; }; inline BGLView * GLView() { return fView; };
inline BGLDispatcher * GLDispatcher() { return fDispatcher; }; inline BGLDispatcher * GLDispatcher() { return fDispatcher; };
private: private:
friend class GLRendererRoster; friend class GLRendererRoster;
virtual status_t _Reserved_Renderer_0(int32, void *); virtual status_t _Reserved_Renderer_0(int32, void *);
virtual status_t _Reserved_Renderer_1(int32, void *); virtual status_t _Reserved_Renderer_1(int32, void *);
virtual status_t _Reserved_Renderer_2(int32, void *); virtual status_t _Reserved_Renderer_2(int32, void *);
virtual status_t _Reserved_Renderer_3(int32, void *); virtual status_t _Reserved_Renderer_3(int32, void *);
virtual status_t _Reserved_Renderer_4(int32, void *); virtual status_t _Reserved_Renderer_4(int32, void *);
volatile int32 fRefCount; // How much we're still usefull? volatile int32 fRefCount; // How much we're still usefull?
BGLView * fView; // Never forget who is the boss! BGLView* fView; // Never forget who is the boss!
ulong fOptions; // Keep that tune in memory ulong fOptions; // Keep that tune in memory
BGLDispatcher * fDispatcher; // Our personal OpenGL API call dispatcher BGLDispatcher* fDispatcher; // Our personal OpenGL API call dispatcher
GLRendererRoster *fOwningRoster; GLRendererRoster* fOwningRoster;
renderer_id fID; renderer_id fID;
}; };
extern "C" _EXPORT BGLRenderer * instantiate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher); extern "C" _EXPORT BGLRenderer * instantiate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher);
@ -68,7 +68,3 @@ extern "C" _EXPORT BGLRenderer * instantiate_gl_renderer(BGLView *view, ulong op
#endif // GLRENDERER_H #endif // GLRENDERER_H

View File

@ -27,7 +27,7 @@ class LinkReceiver {
virtual ~LinkReceiver(void); virtual ~LinkReceiver(void);
void SetPort(port_id port); void SetPort(port_id port);
port_id Port(void) { return fReceivePort; } port_id Port(void) const { return fReceivePort; }
status_t GetNextMessage(int32& code, bigtime_t timeout = B_INFINITE_TIMEOUT); status_t GetNextMessage(int32& code, bigtime_t timeout = B_INFINITE_TIMEOUT);
bool HasMessages() const; bool HasMessages() const;

View File

@ -22,7 +22,7 @@ class LinkSender {
virtual ~LinkSender(void); virtual ~LinkSender(void);
void SetPort(port_id port); void SetPort(port_id port);
port_id Port() { return fPort; } port_id Port() const { return fPort; }
status_t StartMessage(int32 code, size_t minSize = 0); status_t StartMessage(int32 code, size_t minSize = 0);
void CancelMessage(void); void CancelMessage(void);

View File

@ -77,10 +77,10 @@ public:
throw fError; throw fError;
} }
status_t Status() { return fError >= B_OK ? B_OK : fError; }; status_t Status() const { return fError >= B_OK ? B_OK : fError; };
void SetSwap(bool yesNo) { fSwap = yesNo; }; void SetSwap(bool yesNo) { fSwap = yesNo; };
bool IsSwapping() { return fSwap; }; bool IsSwapping() const { return fSwap; };
private: private:
BDataIO *fStream; BDataIO *fStream;

View File

@ -71,7 +71,7 @@ class Autolock {
} }
bool bool
IsLocked() IsLocked() const
{ {
return fStatus == B_OK; return fStatus == B_OK;
} }

View File

@ -82,12 +82,12 @@ public:
return -1; return -1;
} }
int CountItems() int CountItems() const
{ {
return item_count; return item_count;
} }
bool IsEmpty() bool IsEmpty() const
{ {
return item_count == 0; return item_count == 0;
} }

View File

@ -44,16 +44,16 @@ public:
BPath& Path() { return fSettingsPath; } BPath& Path() { return fSettingsPath; }
// General screen saver settings // General screen saver settings
int32 TimeFlags() { return fTimeFlags; } int32 TimeFlags() const { return fTimeFlags; }
bigtime_t BlankTime() { return fBlankTime; } bigtime_t BlankTime() const { return fBlankTime; }
bigtime_t StandByTime() { return fStandByTime; } bigtime_t StandByTime() const { return fStandByTime; }
bigtime_t SuspendTime() { return fSuspendTime; } bigtime_t SuspendTime() const { return fSuspendTime; }
bigtime_t OffTime() { return fOffTime; } bigtime_t OffTime() const { return fOffTime; }
screen_corner BlankCorner() { return fBlankCorner; } screen_corner BlankCorner() const { return fBlankCorner; }
screen_corner NeverBlankCorner() { return fNeverBlankCorner; } screen_corner NeverBlankCorner() const { return fNeverBlankCorner; }
bool LockEnable() { return fLockEnabled; } bool LockEnable() const { return fLockEnabled; }
bigtime_t PasswordTime() { return fPasswordTime; } bigtime_t PasswordTime() const { return fPasswordTime; }
const char* Password() { return fPassword.String(); } const char* Password() { return fPassword.String(); }
const char* LockMethod() { return fLockMethod.String(); } const char* LockMethod() { return fLockMethod.String(); }
bool IsNetworkPassword() bool IsNetworkPassword()
@ -93,8 +93,8 @@ public:
BMessage* stateMessage); BMessage* stateMessage);
// ScreenSaver preferences settings // ScreenSaver preferences settings
BRect WindowFrame() { return fWindowFrame; } BRect WindowFrame() const { return fWindowFrame; }
int32 WindowTab() { return fWindowTab; } int32 WindowTab() const { return fWindowTab; }
void SetWindowFrame(const BRect& frame) void SetWindowFrame(const BRect& frame)
{ fWindowFrame = frame; } { fWindowFrame = frame; }

View File

@ -84,7 +84,7 @@ SET_CURSOR_SHAPE(uint16 width, uint16 height, uint16 hot_x,
scanlineSize = 4 * ((width + 31) / 32); scanlineSize = 4 * ((width + 31) / 32);
scanline = calloc(1, scanlineSize); scanline = calloc(1, scanlineSize);
if (calloc == NULL) if (scanline == NULL)
return B_ERROR; return B_ERROR;
FifoBeginWrite(); FifoBeginWrite();

View File

@ -92,8 +92,10 @@ acpi_device_init_driver(device_node *node, void **cookie)
memset(device, 0, sizeof(*device)); memset(device, 0, sizeof(*device));
if (AcpiGetHandle(NULL, (ACPI_STRING)path, &handle) != AE_OK) if (AcpiGetHandle(NULL, (ACPI_STRING)path, &handle) != AE_OK) {
free(device);
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
}
device->handle = handle; device->handle = handle;
device->path = strdup(path); device->path = strdup(path);

View File

@ -823,15 +823,20 @@ static BusLogic *create_cardinfo(int num, int iobase, int irq)
/* can't be sure of getting contig pages -- scale /* can't be sure of getting contig pages -- scale
stuff down so we can live in just one page */ stuff down so we can live in just one page */
bl->box_count = 4; bl->box_count = 4;
if(!(a = malloc(4096*2))) return NULL; if(!(a = malloc(4096*2))) {
free(bl);
return NULL;
}
a = (uchar *) ((((uint32) a) & 0xFFFFF000) + 0x1000); a = (uchar *) ((((uint32) a) & 0xFFFFF000) + 0x1000);
get_memory_map(a, 4096, entries, 2); get_memory_map(a, 4096, entries, 2);
#else #else
bl->box_count = MAX_CCB_COUNT; bl->box_count = MAX_CCB_COUNT;
aid = create_area("bl_workspace", (void **)&a, B_ANY_KERNEL_ADDRESS, 4096*5, aid = create_area("bl_workspace", (void **)&a, B_ANY_KERNEL_ADDRESS, 4096*5,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if(aid == B_ERROR || aid == B_BAD_VALUE || aid == B_NO_MEMORY) if(aid == B_ERROR || aid == B_BAD_VALUE || aid == B_NO_MEMORY) {
free(bl);
return NULL; return NULL;
}
get_memory_map(a, 4096*5, entries, 2); get_memory_map(a, 4096*5, entries, 2);
#endif #endif

View File

@ -124,8 +124,10 @@ init_words(char *from)
if (fd < B_OK) if (fd < B_OK)
return fd; return fd;
/* lseek() seems to always return 0 from the kernel ??? */ /* lseek() seems to always return 0 from the kernel ??? */
if (fstat(fd, &st)) if (fstat(fd, &st)) {
close(fd);
return B_ERROR; return B_ERROR;
}
sz = (size_t)st.st_size; sz = (size_t)st.st_size;
// sz = (size_t)lseek(fd, 0, SEEK_END); // sz = (size_t)lseek(fd, 0, SEEK_END);
// dprintf("khangman: lseek(): %ld\n", sz); // dprintf("khangman: lseek(): %ld\n", sz);

View File

@ -1155,8 +1155,10 @@ hda_codec_new_audio_group(hda_codec* codec, uint32 audioGroupNodeID)
audioGroup->codec = codec; audioGroup->codec = codec;
audioGroup->multi = (hda_multi*)calloc(1, audioGroup->multi = (hda_multi*)calloc(1,
sizeof(hda_multi)); sizeof(hda_multi));
if (audioGroup->multi == NULL) if (audioGroup->multi == NULL) {
free(audioGroup);
return B_NO_MEMORY; return B_NO_MEMORY;
}
audioGroup->multi->group = audioGroup; audioGroup->multi->group = audioGroup;
/* Parse all widgets in Audio Function Group */ /* Parse all widgets in Audio Function Group */

View File

@ -104,6 +104,8 @@ public:
{ {
} }
virtual ~AbstractLocker() {}
size_t AvailableBytes() const size_t AvailableBytes() const
{ return fBytes; } { return fBytes; }

View File

@ -134,8 +134,10 @@ status_t google_request_process(struct google_request *req)
fd = open(FAKE_INPUT, O_RDONLY, 0644); fd = open(FAKE_INPUT, O_RDONLY, 0644);
if (fd < 0) if (fd < 0)
return -1; return -1;
if (fstat(fd, &st) < 0) if (fstat(fd, &st) < 0) {
close(fd);
return -1; return -1;
}
cnx->datalen = st.st_size; cnx->datalen = st.st_size;
cnx->data = malloc(cnx->datalen); cnx->data = malloc(cnx->datalen);
if (!cnx->data) if (!cnx->data)

View File

@ -2748,8 +2748,10 @@ ClientConnection::_CreateVolume(ClientVolume** _volume)
if (!volume) if (!volume)
return B_NO_MEMORY; return B_NO_MEMORY;
status_t error = volume->Init(); status_t error = volume->Init();
if (error != B_OK) if (error != B_OK) {
delete volume;
return error; return error;
}
// add it to the volume map // add it to the volume map
AutoLocker<VolumeMap> locker(fVolumes); AutoLocker<VolumeMap> locker(fVolumes);

View File

@ -790,8 +790,10 @@ NetFSServer::_LoadSecurityContext(SecurityContext** _securityContext)
if (!securityContext) if (!securityContext)
return B_NO_MEMORY; return B_NO_MEMORY;
status_t error = securityContext->InitCheck(); status_t error = securityContext->InitCheck();
if (error != B_OK) if (error != B_OK) {
delete securityContext;
return error; return error;
}
ObjectDeleter<SecurityContext> securityContextDeleter(securityContext); ObjectDeleter<SecurityContext> securityContextDeleter(securityContext);
// load from driver settings for the time being // load from driver settings for the time being

View File

@ -796,7 +796,7 @@ PRINT(("VolumeManager::OpenQuery(%p, \"%s\", 0x%lx, %ld, %ld)\n", queryDomain, q
// allocate the handle // allocate the handle
QueryHandle* queryHandle = new(std::nothrow) QueryHandle(remotePort, QueryHandle* queryHandle = new(std::nothrow) QueryHandle(remotePort,
remoteToken); remoteToken);
if (!handle) if (!queryHandle)
return B_NO_MEMORY; return B_NO_MEMORY;
ObjectDeleter<QueryHandle> handleDeleter(queryHandle); ObjectDeleter<QueryHandle> handleDeleter(queryHandle);

View File

@ -21,7 +21,7 @@
class PartitionLocker { class PartitionLocker {
public: public:
PartitionLocker(partition_id partitionID); PartitionLocker(partition_id partitionID);
~PartitionLocker(); virtual ~PartitionLocker();
bool IsLocked() const; bool IsLocked() const;
partition_id PartitionId() const; partition_id PartitionId() const;

View File

@ -21,7 +21,7 @@
class PartitionLocker { class PartitionLocker {
public: public:
PartitionLocker(partition_id partitionID); PartitionLocker(partition_id partitionID);
~PartitionLocker(); virtual ~PartitionLocker();
bool IsLocked() const; bool IsLocked() const;
partition_id PartitionId() const; partition_id PartitionId() const;

View File

@ -627,8 +627,11 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
const color_map *pmap = NULL; const color_map *pmap = NULL;
if (fromspace == B_CMAP8) { if (fromspace == B_CMAP8) {
pmap = system_colors(); pmap = system_colors();
if (!pmap) if (!pmap) {
delete [] bmpRowData;
delete [] bitsRowData;
return B_ERROR; return B_ERROR;
}
} }
while (rd == static_cast<ssize_t>(bitsRowBytes)) { while (rd == static_cast<ssize_t>(bitsRowBytes)) {

View File

@ -591,6 +591,7 @@ Table::TableRowsAdded(TableModel* model, int32 rowIndex, int32 count)
TableField* field = new(std::nothrow) TableField(i); TableField* field = new(std::nothrow) TableField(i);
if (field == NULL) { if (field == NULL) {
// TODO: Report error! // TODO: Report error!
delete row;
return; return;
} }

View File

@ -64,8 +64,10 @@ SetGradientCommand::Perform()
*fGradient = *fStyle->Gradient(); *fGradient = *fStyle->Gradient();
else { else {
fGradient = new (nothrow) Gradient(*fStyle->Gradient()); fGradient = new (nothrow) Gradient(*fStyle->Gradient());
if (!fGradient) if (!fGradient) {
delete clone;
return B_NO_MEMORY; return B_NO_MEMORY;
}
} }
} else { } else {
// the style didn't have a gradient set // the style didn't have a gradient set

View File

@ -24,18 +24,18 @@ class AreaLinkHeader {
AreaLinkHeader() { MakeEmpty(); fLock = B_NAME_NOT_FOUND; } AreaLinkHeader() { MakeEmpty(); fLock = B_NAME_NOT_FOUND; }
void SetAttachmentCount(uint32 size) { fAttachmentCount = size; } void SetAttachmentCount(uint32 size) { fAttachmentCount = size; }
uint32 GetAttachmentCount() { return fAttachmentCount; } uint32 GetAttachmentCount() const { return fAttachmentCount; }
void SetAttachmentSize(uint32 size) { fAttachmentSize = size; } void SetAttachmentSize(uint32 size) { fAttachmentSize = size; }
uint32 GetAttachmentSize() { return fAttachmentSize; } uint32 GetAttachmentSize() const { return fAttachmentSize; }
void AddAttachment(uint32 size) { fAttachmentSize += size; fAttachmentCount++; } void AddAttachment(uint32 size) { fAttachmentSize += size; fAttachmentCount++; }
void SetLockSem(sem_id sem) { fLock = sem; } void SetLockSem(sem_id sem) { fLock = sem; }
sem_id GetLockSem() { return fLock; } sem_id GetLockSem() const { return fLock; }
void MakeEmpty() { fAttachmentCount = 0; fAttachmentSize = 0; } void MakeEmpty() { fAttachmentCount = 0; fAttachmentSize = 0; }
area_info GetInfo() { return fInfo; } area_info GetInfo() const { return fInfo; }
void SetInfo(const area_info &newInfo) { fInfo = newInfo; } void SetInfo(const area_info &newInfo) { fInfo = newInfo; }
private: private:
@ -61,8 +61,9 @@ AreaLink::AreaLink()
:fAttachList(new BList(0)), :fAttachList(new BList(0)),
fTarget(B_NAME_NOT_FOUND), fTarget(B_NAME_NOT_FOUND),
fAreaIsOk(false), fAreaIsOk(false),
fHaveLock(false) fHaveLock(false),
fBaseAddress(0),
fHeader(0)
{ {
} }

View File

@ -16,10 +16,11 @@ BMessenger* _RetrieveBluetoothMessenger(void)
// Fix/review: leaking memory here // Fix/review: leaking memory here
BMessenger* fMessenger = new BMessenger(BLUETOOTH_SIGNATURE); BMessenger* fMessenger = new BMessenger(BLUETOOTH_SIGNATURE);
if (fMessenger == NULL || !fMessenger->IsValid()) if (fMessenger == NULL || !fMessenger->IsValid()) {
return NULL; delete fMessenger;
else return NULL;
return fMessenger; } else
return fMessenger;
} }
@ -32,5 +33,5 @@ uint8 GetInquiryTime()
void SetInquiryTime(uint8 time) void SetInquiryTime(uint8 time)
{ {
((void)(time)); ((void)(time));
} }

View File

@ -17,6 +17,7 @@
BListItem::BListItem(uint32 level, bool expanded) BListItem::BListItem(uint32 level, bool expanded)
: :
fTop(0.0), fTop(0.0),
fTemporaryList(0),
fWidth(0), fWidth(0),
fHeight(0), fHeight(0),
fLevel(level), fLevel(level),

View File

@ -550,8 +550,10 @@ _BPictureExtent_::Unflatten(BDataIO *stream)
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
BPicture* picture = new BPicture; BPicture* picture = new BPicture;
status_t status = picture->Unflatten(stream); status_t status = picture->Unflatten(stream);
if (status < B_OK) if (status < B_OK) {
delete picture;
return status; return status;
}
AddPicture(picture); AddPicture(picture);
} }

View File

@ -92,7 +92,8 @@ BCollator::BCollator(BCollatorAddOn *collator, int8 strength,
BCollator::BCollator(BMessage *archive) BCollator::BCollator(BMessage *archive)
: BArchivable(archive), : BArchivable(archive),
fCollator(NULL), fCollator(NULL),
fCollatorImage(B_ERROR) fCollatorImage(B_ERROR),
fIgnorePunctuation(true)
{ {
#if HAIKU_TARGET_PLATFORM_HAIKU #if HAIKU_TARGET_PLATFORM_HAIKU
int32 data; int32 data;

View File

@ -1016,6 +1016,9 @@ BGenericNumberFormat::BGenericNumberFormat()
// destructor // destructor
BGenericNumberFormat::~BGenericNumberFormat() BGenericNumberFormat::~BGenericNumberFormat()
{ {
delete fSignSymbols;
delete fMantissaSignSymbols;
delete fExponentSignSymbols;
} }
// FormatInteger // FormatInteger

View File

@ -93,8 +93,7 @@ BLanguage::BLanguage(const char *language)
BLanguage::~BLanguage() BLanguage::~BLanguage()
{ {
if (fICULocale != NULL) delete fICULocale;
delete fICULocale;
for (int32 i = B_NUM_LANGUAGE_STRINGS;i-- > 0;) for (int32 i = B_NUM_LANGUAGE_STRINGS;i-- > 0;)
free(fStrings[i]); free(fStrings[i]);

View File

@ -189,6 +189,7 @@ BNumberFormatParameters::operator=(const BNumberFormatParameters &other)
fUseBasePrefix = other.fUseBasePrefix; fUseBasePrefix = other.fUseBasePrefix;
fMinimalIntegerDigits = other.fMinimalIntegerDigits; fMinimalIntegerDigits = other.fMinimalIntegerDigits;
fFlags = other.fFlags; fFlags = other.fFlags;
fUseZeroPadding = other.fUseZeroPadding;
return *this; return *this;
} }

View File

@ -476,9 +476,7 @@ BMailChainRunner::get_messages(BStringList *list)
if (err == B_MAIL_DISCARD) if (err == B_MAIL_DISCARD)
entry->Remove(); entry->Remove();
if (file != NULL) delete file;
delete file;
delete entry; delete entry;
delete headers; delete headers;
delete folder; delete folder;

View File

@ -419,8 +419,7 @@ BAttributedMailAttachment::~BAttributedMailAttachment() {
status_t BAttributedMailAttachment::Initialize() status_t BAttributedMailAttachment::Initialize()
{ {
// _data & _attributes_attach will be deleted by the container // _data & _attributes_attach will be deleted by the container
if (fContainer != NULL) delete fContainer;
delete fContainer;
fContainer = new BMIMEMultipartMailContainer("++++++BFile++++++"); fContainer = new BMIMEMultipartMailContainer("++++++BFile++++++");
@ -639,8 +638,10 @@ status_t BAttributedMailAttachment::RenderToRFC822(BPositionIO *render_to) {
io->Write(&swapped,sizeof(int64)); io->Write(&swapped,sizeof(int64));
void *allocd = malloc(dataLen); void *allocd = malloc(dataLen);
if (allocd == NULL) if (allocd == NULL) {
delete io;
return B_NO_MEMORY; return B_NO_MEMORY;
}
memcpy(allocd,data,dataLen); memcpy(allocd,data,dataLen);
swap_data(type, allocd, dataLen, B_SWAP_HOST_TO_BENDIAN); swap_data(type, allocd, dataLen, B_SWAP_HOST_TO_BENDIAN);
io->Write(allocd,dataLen); io->Write(allocd,dataLen);

View File

@ -41,8 +41,7 @@ BMailChain::BMailChain(BMessage* settings)
BMailChain::~BMailChain() { BMailChain::~BMailChain() {
if (meta_data != NULL) delete meta_data;
delete meta_data;
for (int32 i = 0; filter_settings.ItemAt(i); i++) for (int32 i = 0; filter_settings.ItemAt(i); i++)
delete (BMessage *)filter_settings.ItemAt(i); delete (BMessage *)filter_settings.ItemAt(i);
@ -53,8 +52,7 @@ BMailChain::~BMailChain() {
status_t BMailChain::Load(BMessage* settings) status_t BMailChain::Load(BMessage* settings)
{ {
if (meta_data != NULL) delete meta_data;
delete meta_data;
meta_data = new BMessage; meta_data = new BMessage;
if (settings->HasMessage("meta_data")) if (settings->HasMessage("meta_data"))

View File

@ -96,8 +96,7 @@ BEmailMessage::BEmailMessage(entry_ref *ref, uint32 defaultCharSet)
BEmailMessage::~BEmailMessage() BEmailMessage::~BEmailMessage()
{ {
if (_bcc != NULL) free(_bcc);
free(_bcc);
delete _body; delete _body;
delete fData; delete fData;
@ -327,8 +326,7 @@ void BEmailMessage::SetCC(const char *cc, uint32 charset, mail_encoding encoding
} }
void BEmailMessage::SetBCC(const char *bcc) { void BEmailMessage::SetBCC(const char *bcc) {
if (_bcc != NULL) free(_bcc);
free(_bcc);
_bcc = strdup(bcc); _bcc = strdup(bcc);
} }

View File

@ -308,8 +308,8 @@ BBufferConsumer::SetOutputBuffersFor(const media_source &source,
free(command); free(command);
if (rv == B_OK) { if (rv == B_OK) {
if (fDeleteBufferGroup) // XXX will leak memory if port write failed // XXX will leak memory if port write failed
delete fDeleteBufferGroup; delete fDeleteBufferGroup;
fDeleteBufferGroup = will_reclaim ? NULL : group; fDeleteBufferGroup = will_reclaim ? NULL : group;
} }
return rv; return rv;

View File

@ -1990,8 +1990,10 @@ BDiscreteParameter::AddItem(int32 value, const char* name)
int32* valueCopy = new int32(value); int32* valueCopy = new int32(value);
char* nameCopy = strndup(name, 255); char* nameCopy = strndup(name, 255);
if (name != NULL && nameCopy == NULL) if (name != NULL && nameCopy == NULL) {
delete valueCopy;
return B_NO_MEMORY; return B_NO_MEMORY;
}
if (!fValues->AddItem(valueCopy) || !fSelections->AddItem(nameCopy)) if (!fValues->AddItem(valueCopy) || !fSelections->AddItem(nameCopy))
return B_NO_MEMORY; return B_NO_MEMORY;

View File

@ -441,8 +441,7 @@ BAppFileInfo::GetSupportedTypes(BMessage *types) const
if (error == B_OK) if (error == B_OK)
error = types->Unflatten((const char*)buffer); error = types->Unflatten((const char*)buffer);
// clean up // clean up
if (buffer) free(buffer);
free(buffer);
return error; return error;
} }
@ -517,8 +516,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll)
buffer, size); buffer, size);
} }
// clean up // clean up
if (buffer) delete[] buffer;
delete[] buffer;
} else } else
error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE); error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE);
// update the MIME database, if the app signature is installed // update the MIME database, if the app signature is installed

View File

@ -976,13 +976,17 @@ BPathMonitor::StartWatching(const char* path, uint32 flags, BMessenger target)
if (handler == NULL) if (handler == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
status = handler->InitCheck(); status = handler->InitCheck();
if (status < B_OK) if (status < B_OK) {
delete handler;
return status; return status;
}
if (watcher == NULL) { if (watcher == NULL) {
watcher = new (nothrow) BPrivate::Watcher; watcher = new (nothrow) BPrivate::Watcher;
if (watcher == NULL) if (watcher == NULL) {
delete handler;
return B_NO_MEMORY; return B_NO_MEMORY;
}
sWatchers[target] = watcher; sWatchers[target] = watcher;
} }

View File

@ -41,7 +41,7 @@ private:
}; };
#if __GNUC__ > 2 #if __GNUC__ > 3
BStatable::~BStatable() BStatable::~BStatable()
{ {
} }

View File

@ -425,8 +425,7 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, size_t neededSize,
(user_disk_device_data*)buffer, bufferSize, &neededSize); (user_disk_device_data*)buffer, bufferSize, &neededSize);
if (error == B_BUFFER_OVERFLOW) { if (error == B_BUFFER_OVERFLOW) {
// buffer to small re-allocate it // buffer to small re-allocate it
if (buffer) free(buffer);
free(buffer);
buffer = malloc(neededSize); buffer = malloc(neededSize);
@ -440,7 +439,7 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, size_t neededSize,
// set result / cleanup on error // set result / cleanup on error
if (error == B_OK) if (error == B_OK)
*data = (user_disk_device_data*)buffer; *data = (user_disk_device_data*)buffer;
else if (buffer) else
free(buffer); free(buffer);
return error; return error;

View File

@ -36,8 +36,7 @@ BDiskDeviceList::BDiskDeviceList(bool useOwnLocker)
*/ */
BDiskDeviceList::~BDiskDeviceList() BDiskDeviceList::~BDiskDeviceList()
{ {
if (fLocker) delete fLocker;
delete fLocker;
} }
// MessageReceived // MessageReceived

View File

@ -182,12 +182,9 @@ PartitioningDialog::_Init(BDiskScannerParameterEditor *editor)
delete okMessage; delete okMessage;
if (!cancelButton && cancelMessage) if (!cancelButton && cancelMessage)
delete cancelMessage; delete cancelMessage;
if (okButton) delete okButton;
delete okButton; delete cancelButton;
if (cancelButton) delete mainView;
delete cancelButton;
if (mainView)
delete mainView;
} }
} }
return error; return error;

View File

@ -766,8 +766,7 @@ Model::SetLinkTo(Model *model)
ASSERT(IsSymLink()); ASSERT(IsSymLink());
ASSERT(!fLinkTo || (fLinkTo != model)); ASSERT(!fLinkTo || (fLinkTo != model));
if (fLinkTo) delete fLinkTo;
delete fLinkTo;
fLinkTo = model; fLinkTo = model;
} }

View File

@ -409,8 +409,8 @@ void
OffscreenBitmap::NewBitmap(BRect bounds) OffscreenBitmap::NewBitmap(BRect bounds)
{ {
delete fBitmap; delete fBitmap;
fBitmap = new BBitmap(bounds, B_RGB32, true); fBitmap = new(std::nothrow) BBitmap(bounds, B_RGB32, true);
if (fBitmap->Lock()) { if (fBitmap && fBitmap->Lock()) {
BView *view = new BView(fBitmap->Bounds(), "", B_FOLLOW_NONE, 0); BView *view = new BView(fBitmap->Bounds(), "", B_FOLLOW_NONE, 0);
fBitmap->AddChild(view); fBitmap->AddChild(view);

View File

@ -30,5 +30,6 @@ int main(int argc, char **argv)
*p++ = (uint8_t)sum; *p++ = (uint8_t)sum;
//lseek(fd, 0LL, SEEK_SET); //lseek(fd, 0LL, SEEK_SET);
write(fd, &sector[512-2], 2); write(fd, &sector[512-2], 2);
close(fd);
return 0; return 0;
} }

View File

@ -771,6 +771,7 @@ platform_add_boot_device(struct stage2_args *args, NodeList *devicesList)
BIOSDrive *drive = new(nothrow) BIOSDrive(gBootDriveID); BIOSDrive *drive = new(nothrow) BIOSDrive(gBootDriveID);
if (drive->InitCheck() != B_OK) { if (drive->InitCheck() != B_OK) {
dprintf("no boot drive!\n"); dprintf("no boot drive!\n");
delete drive;
return B_ERROR; return B_ERROR;
} }

View File

@ -58,7 +58,7 @@ struct file_cache_ref {
last_access[index] = isWrite ? -access : access; last_access[index] = isWrite ? -access : access;
} }
inline off_t LastAccess(int32 index, bool isWrite) inline off_t LastAccess(int32 index, bool isWrite) const
{ {
return isWrite ? -last_access[index] : last_access[index]; return isWrite ? -last_access[index] : last_access[index];
} }

View File

@ -1933,8 +1933,7 @@ elf_load_user_image(const char *path, struct team *team, int flags,
status = B_OK; status = B_OK;
error: error:
if (programHeaders) free(programHeaders);
free(programHeaders);
_kern_close(fd); _kern_close(fd);
return status; return status;

View File

@ -796,6 +796,7 @@ _user_xsi_semget(key_t key, int numberOfSemaphores, int flags)
if (semaphoreSet == NULL || !semaphoreSet->InitOK()) { if (semaphoreSet == NULL || !semaphoreSet->InitOK()) {
TRACE_ERROR(("xsi_semget: failed to allocate a new xsi " TRACE_ERROR(("xsi_semget: failed to allocate a new xsi "
"semaphore set\n")); "semaphore set\n"));
delete semaphoreSet;
return ENOMEM; return ENOMEM;
} }
atomic_add(&sXsiSemaphoreCount, numberOfSemaphores); atomic_add(&sXsiSemaphoreCount, numberOfSemaphores);

View File

@ -1495,16 +1495,14 @@ thread_exit(void)
TRACE(("thread_exit: thread %ld now a kernel thread!\n", thread->id)); TRACE(("thread_exit: thread %ld now a kernel thread!\n", thread->id));
} }
if (threadDeathEntry != NULL) free(threadDeathEntry);
free(threadDeathEntry);
// delete the team if we're its main thread // delete the team if we're its main thread
if (deleteTeam) { if (deleteTeam) {
team_delete_team(team, debuggerPort); team_delete_team(team, debuggerPort);
// we need to delete any death entry that made it to here // we need to delete any death entry that made it to here
if (death != NULL) delete death;
delete death;
} }
state = disable_interrupts(); state = disable_interrupts();

View File

@ -128,8 +128,7 @@ fixed_queue_init(fixed_queue *q, int size)
void void
fixed_queue_destroy(fixed_queue *q) fixed_queue_destroy(fixed_queue *q)
{ {
if (q->table) free(q->table);
free(q->table);
} }

View File

@ -635,8 +635,10 @@ driver_settings_init(kernel_args *args)
if (settings->size != 0) { if (settings->size != 0) {
handle->text = malloc(settings->size + 1); handle->text = malloc(settings->size + 1);
if (handle->text == NULL) if (handle->text == NULL) {
free(handle);
return B_NO_MEMORY; return B_NO_MEMORY;
}
memcpy(handle->text, settings->buffer, settings->size); memcpy(handle->text, settings->buffer, settings->size);
handle->text[settings->size] = '\0'; handle->text[settings->size] = '\0';
@ -782,6 +784,7 @@ load_driver_settings(const char *driverName)
#ifdef _KERNEL_MODE #ifdef _KERNEL_MODE
mutex_unlock(&sLock); mutex_unlock(&sLock);
#endif #endif
close(file);
return NULL; return NULL;
} }

View File

@ -447,7 +447,7 @@ class DateMask {
bool IsComplete(); bool IsComplete();
private: private:
inline uint32 Flag(uint8 type) { return 1UL << type; } inline uint32 Flag(uint8 type) const { return 1UL << type; }
uint32 fMask; uint32 fMask;
}; };

View File

@ -335,8 +335,10 @@ scandir(const char* path, struct dirent*** _entryArray,
arrayCapacity *= 2; arrayCapacity *= 2;
newArray = realloc(array, arrayCapacity * sizeof(void*)); newArray = realloc(array, arrayCapacity * sizeof(void*));
if (newArray == NULL) if (newArray == NULL) {
free(copiedEntry);
goto error; goto error;
}
array = newArray; array = newArray;
} }