diff --git a/headers/private/package/hpkg/Strings.h b/headers/private/package/hpkg/Strings.h index afdbd826e6..dcd4da9e4d 100644 --- a/headers/private/package/hpkg/Strings.h +++ b/headers/private/package/hpkg/Strings.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ #ifndef _PACKAGE__HPKG__PRIVATE__STRINGS_H_ @@ -89,11 +89,11 @@ struct CachedStringUsageGreater { struct StringCache : public CachedStringTable { - StringCache(); - ~StringCache(); - - CachedString* Get(const char* value); + StringCache(); + ~StringCache(); + CachedString* Get(const char* value); + void Put(CachedString* string); }; diff --git a/src/kits/package/hpkg/PackageWriterImpl.cpp b/src/kits/package/hpkg/PackageWriterImpl.cpp index cf2dd504ec..7d52ed9190 100644 --- a/src/kits/package/hpkg/PackageWriterImpl.cpp +++ b/src/kits/package/hpkg/PackageWriterImpl.cpp @@ -1052,7 +1052,8 @@ PackageWriterImpl::_AttributeRemoved(Attribute* attribute) && value.encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP) { if (!fHeapRangesToRemove->AddRange(value.data.offset, value.data.size)) throw std::bad_alloc(); - } + } else if (value.type == B_HPKG_ATTRIBUTE_TYPE_STRING) + fStringCache.Put(value.string); for (DoublyLinkedList::Iterator it = attribute->children.GetIterator(); diff --git a/src/kits/package/hpkg/Strings.cpp b/src/kits/package/hpkg/Strings.cpp index 4f87d8e20c..32210fd2f4 100644 --- a/src/kits/package/hpkg/Strings.cpp +++ b/src/kits/package/hpkg/Strings.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ @@ -70,6 +70,18 @@ StringCache::Get(const char* value) } +void +StringCache::Put(CachedString* string) +{ + if (string != NULL) { + if (--string->usageCount == 0) { + Remove(string); + delete string; + } + } +} + + } // namespace BPrivate } // namespace BHPKG