diff --git a/src/add-ons/opengl/swpipe/GalliumContext.cpp b/src/add-ons/opengl/swpipe/GalliumContext.cpp index 3a9a22911a..6e91cd08e0 100644 --- a/src/add-ons/opengl/swpipe/GalliumContext.cpp +++ b/src/add-ons/opengl/swpipe/GalliumContext.cpp @@ -73,10 +73,14 @@ hgl_viewport(struct gl_context* glContext, GLint x, GLint y, } -static void -hgl_fill_st_visual(st_visual* stVisual, gl_config* glVisual) +static st_visual* +hgl_fill_st_visual(gl_config* glVisual) { - memset(stVisual, 0, sizeof(*stVisual)); + struct st_visual* stVisual = CALLOC_STRUCT(st_visual); + if (!stVisual) { + ERROR("%s: Couldn't allocate st_visual\n", __func__); + return NULL; + } // Determine color format if (glVisual->redBits == 8) { @@ -129,6 +133,8 @@ hgl_fill_st_visual(st_visual* stVisual, gl_config* glVisual) if (glVisual->haveDepthBuffer || glVisual->haveStencilBuffer) stVisual->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK; + + return stVisual; } @@ -292,11 +298,10 @@ GalliumContext::CreateContext(Bitmap *bitmap) TRACE("stencilBits :\t%d\n", glVisual->stencilBits); // Convert Mesa calculated visual into state tracker visual - struct st_visual stVisual; - hgl_fill_st_visual(&stVisual, glVisual); + context->stVisual = hgl_fill_st_visual(glVisual); - context->draw = new GalliumFramebuffer(&stVisual); - context->read = new GalliumFramebuffer(&stVisual); + context->draw = new GalliumFramebuffer(context->stVisual); + context->read = new GalliumFramebuffer(context->stVisual); if (!context->draw || !context->read) { ERROR("%s: Problem allocating framebuffer!\n", __func__); @@ -312,7 +317,7 @@ GalliumContext::CreateContext(Bitmap *bitmap) memset(&attribs, 0, sizeof(attribs)); attribs.options.force_glsl_extensions_warn = false; attribs.profile = ST_PROFILE_DEFAULT; - attribs.visual = stVisual; + attribs.visual = *context->stVisual; attribs.major = 1; attribs.minor = 0; //attribs.flags |= ST_CONTEXT_FLAG_DEBUG; @@ -418,6 +423,9 @@ GalliumContext::DestroyContext(context_id contextID) if (fContext[contextID]->draw) delete fContext[contextID]->draw; + if (fContext[contextID]->stVisual) + FREE(fContext[contextID]->stVisual); + if (fContext[contextID]->manager) FREE(fContext[contextID]->manager); diff --git a/src/apps/debugger/controllers/DebugReportGenerator.cpp b/src/apps/debugger/controllers/DebugReportGenerator.cpp index 12b4fa25dd..996e67f631 100644 --- a/src/apps/debugger/controllers/DebugReportGenerator.cpp +++ b/src/apps/debugger/controllers/DebugReportGenerator.cpp @@ -32,8 +32,6 @@ DebugReportGenerator::DebugReportGenerator(::Team* team) : BLooper("DebugReportGenerator"), - BReferenceable(), - fTeam(team), fArchitecture(team->GetArchitecture()), fTeamDataSem(-1) diff --git a/src/apps/debugger/controllers/DebugReportGenerator.h b/src/apps/debugger/controllers/DebugReportGenerator.h index 1267586aee..1ea4dff8e0 100644 --- a/src/apps/debugger/controllers/DebugReportGenerator.h +++ b/src/apps/debugger/controllers/DebugReportGenerator.h @@ -7,7 +7,6 @@ #include -#include #include "Team.h" @@ -19,9 +18,7 @@ class Team; class Thread; -class DebugReportGenerator : public BLooper, public BReferenceable, - public Team::Listener -{ +class DebugReportGenerator : public BLooper, public Team::Listener { public: DebugReportGenerator(::Team* team); ~DebugReportGenerator(); diff --git a/src/apps/debugger/controllers/TeamDebugger.cpp b/src/apps/debugger/controllers/TeamDebugger.cpp index 3e92cb12d0..6c8f43ecd2 100644 --- a/src/apps/debugger/controllers/TeamDebugger.cpp +++ b/src/apps/debugger/controllers/TeamDebugger.cpp @@ -284,7 +284,6 @@ TeamDebugger::~TeamDebugger() delete fMemoryBlockManager; fReportGenerator->Lock(); fReportGenerator->Quit(); - delete fReportGenerator; delete fWorker; delete fTeam; delete fFileManager; diff --git a/src/apps/debugger/dwarf/DwarfManager.cpp b/src/apps/debugger/dwarf/DwarfManager.cpp index 5d02dfed71..b6fb6bfadb 100644 --- a/src/apps/debugger/dwarf/DwarfManager.cpp +++ b/src/apps/debugger/dwarf/DwarfManager.cpp @@ -41,13 +41,14 @@ DwarfManager::LoadFile(const char* fileName, DwarfFile*& _file) if (file == NULL) return B_NO_MEMORY; + BReference fileReference(file, true); status_t error = file->Load(fileName); if (error != B_OK) { - delete file; return error; } fFiles.Add(file); + fileReference.Detach(); // we keep the initial reference for ourselves file->AcquireReference(); diff --git a/src/apps/debugger/value/value_nodes/BListValueNode.cpp b/src/apps/debugger/value/value_nodes/BListValueNode.cpp index 91ea46f2b6..bd0073f931 100644 --- a/src/apps/debugger/value/value_nodes/BListValueNode.cpp +++ b/src/apps/debugger/value/value_nodes/BListValueNode.cpp @@ -246,29 +246,28 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, if (strcmp(member->Name(), "fObjectList") == 0) { error = baseType->ResolveDataMemberLocation(member, *location, memberLocation); + BReference locationRef(memberLocation, true); if (error != B_OK) { TRACE_LOCALS( "BListValueNode::ResolvedLocationAndValue(): " "failed to resolve location of header member: %s\n", strerror(error)); - delete memberLocation; return error; } error = valueLoader->LoadValue(memberLocation, valueType, false, fDataLocation); - delete memberLocation; if (error != B_OK) return error; } else if (strcmp(member->Name(), "fItemCount") == 0) { error = baseType->ResolveDataMemberLocation(member, *location, memberLocation); + BReference locationRef(memberLocation, true); if (error != B_OK) { TRACE_LOCALS( "BListValueNode::ResolvedLocationAndValue(): " "failed to resolve location of header member: %s\n", strerror(error)); - delete memberLocation; return error; } @@ -280,7 +279,6 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, BVariant listSize; error = valueLoader->LoadValue(memberLocation, valueType, false, listSize); - delete memberLocation; if (error != B_OK) return error; diff --git a/src/apps/terminal/AppearPrefView.cpp b/src/apps/terminal/AppearPrefView.cpp index 7da4e58cd4..06b11900f4 100644 --- a/src/apps/terminal/AppearPrefView.cpp +++ b/src/apps/terminal/AppearPrefView.cpp @@ -291,6 +291,7 @@ AppearancePrefView::MessageReceived(BMessage* msg) _EnableCustomColors(true); else _EnableCustomColors(false); + _ChangeColorScheme(newScheme); modified = true; } @@ -393,14 +394,12 @@ AppearancePrefView::_SetCurrentColorScheme(BMenuField* field) const char* currentSchemeName = NULL; - color_scheme** schemes - = const_cast(gPredefinedColorSchemes); - while (*schemes) { + for (const color_scheme** schemes = gPredefinedColorSchemes; + *schemes != NULL; schemes++) { if (gCustomColorScheme == **schemes) { currentSchemeName = (*schemes)->name; break; } - schemes++; } for (int32 i = 0; i < fColorSchemeField->Menu()->CountItems(); i++) { diff --git a/src/apps/terminal/Colors.cpp b/src/apps/terminal/Colors.cpp index 7125514330..56cbbea212 100644 --- a/src/apps/terminal/Colors.cpp +++ b/src/apps/terminal/Colors.cpp @@ -14,7 +14,7 @@ // Standard colors -const rgb_color kBlack= { 0, 0, 0, 255 }; +const rgb_color kBlack = { 0, 0, 0, 255 }; const rgb_color kGreen = { 0, 255, 0, 255 }; const rgb_color kWhite = { 255, 255, 255, 255 }; const rgb_color kYellow = { 255, 255, 0, 255 }; @@ -35,7 +35,7 @@ const struct color_scheme kColorSchemeBlue = { kYellow, { 0, 0, 139, 255 }, kBlack, - kWhite, + kYellow, kBlack, { 0, 139, 139, 255 }, }; @@ -85,27 +85,24 @@ struct color_scheme gCustomColorScheme = { }; const color_scheme* gPredefinedColorSchemes[] = { - &kColorSchemeDefault, - &kColorSchemeBlue, - &kColorSchemeMidnight, - &kColorSchemeProfessional, - &kColorSchemeRetro, - &kColorSchemeSlate, - &gCustomColorScheme, - NULL + &kColorSchemeDefault, + &kColorSchemeBlue, + &kColorSchemeMidnight, + &kColorSchemeProfessional, + &kColorSchemeRetro, + &kColorSchemeSlate, + &gCustomColorScheme, + NULL }; bool color_scheme::operator==(const color_scheme& scheme) { - if (text_fore_color == scheme.text_fore_color + return text_fore_color == scheme.text_fore_color && text_back_color == scheme.text_back_color && cursor_fore_color == scheme.cursor_fore_color && cursor_back_color == scheme.cursor_back_color && select_fore_color == scheme.select_fore_color - && select_back_color == scheme.select_back_color) - return true; - - return false; + && select_back_color == scheme.select_back_color; } diff --git a/src/apps/terminal/PrefHandler.cpp b/src/apps/terminal/PrefHandler.cpp index 41f96bf0db..7c120f7db4 100644 --- a/src/apps/terminal/PrefHandler.cpp +++ b/src/apps/terminal/PrefHandler.cpp @@ -44,7 +44,7 @@ static const pref_defaults kTermDefaults[] = { { PREF_TEXT_FORE_COLOR, " 0, 0, 0" }, { PREF_TEXT_BACK_COLOR, "255, 255, 255" }, - { PREF_CURSOR_FORE_COLOR, " 0, 0, 0" }, + { PREF_CURSOR_FORE_COLOR, "255, 255, 255" }, { PREF_CURSOR_BACK_COLOR, " 0, 0, 0" }, { PREF_SELECT_FORE_COLOR, "255, 255, 255" }, { PREF_SELECT_BACK_COLOR, " 0, 0, 0" }, diff --git a/src/kits/support/Referenceable.cpp b/src/kits/support/Referenceable.cpp index 6b2ee363b0..1aaedec5d9 100644 --- a/src/kits/support/Referenceable.cpp +++ b/src/kits/support/Referenceable.cpp @@ -27,8 +27,31 @@ BReferenceable::BReferenceable() BReferenceable::~BReferenceable() { #ifdef DEBUG - if (fReferenceCount > 1) - debugger("Deleted object which still had references.\n"); + bool enterDebugger = false; + if (fReferenceCount == 1) { + // Simple heuristic to test if this object was allocated + // on the stack: check if this is within 1KB in either + // direction of the current stack address, and the reference + // count is 1. If so, we don't flag a warning since that would + // imply the object was allocated/destroyed on the stack + // without any references being acquired or released. + char test; + size_t testOffset = (addr_t)this - (addr_t)&test; + if (testOffset > 1024 || -testOffset > 1024) { + // might still be a stack object, check the thread's + // stack range to be sure. + thread_info info; + status_t result = get_thread_info(find_thread(NULL), &info); + if (result != B_OK || this < info.stack_base + || this > info.stack_end) { + enterDebugger = true; + } + } + } else if (fReferenceCount != 0) + enterDebugger = true; + + if (enterDebugger) + debugger("Deleted referenceable object with non-zero ref count."); #endif } diff --git a/src/kits/support/StringList.cpp b/src/kits/support/StringList.cpp index 900322d967..7b453d825a 100644 --- a/src/kits/support/StringList.cpp +++ b/src/kits/support/StringList.cpp @@ -17,16 +17,16 @@ static int compare_private_data(const void* a, const void* b) { - return BString::Private::StringFromData((char*)a).Compare( - BString::Private::StringFromData((char*)b)); + return BString::Private::StringFromData(*(char**)a).Compare( + BString::Private::StringFromData(*(char**)b)); } static int compare_private_data_ignore_case(const void* a, const void* b) { - return BString::Private::StringFromData((char*)a).ICompare( - BString::Private::StringFromData((char*)b)); + return BString::Private::StringFromData(*(char**)a).ICompare( + BString::Private::StringFromData(*(char**)b)); } @@ -367,7 +367,7 @@ BStringList::Flatten(void* buf, ssize_t size) const if (size < FlattenedSize()) return B_NO_MEMORY; - + int32 count = CountStrings(); for (int32 i = 0; i < count; i++) { BString item = StringAt(i); @@ -403,7 +403,7 @@ BStringList::Unflatten(type_code code, const void* buffer, ssize_t size) } return B_OK; -} +} void