Another RAII member.

This commit is contained in:
2025-08-18 03:10:56 -04:00
parent b1e1f8e98e
commit 871a6e72e1

View File

@ -51,7 +51,7 @@ struct CacheEntry_t
~CacheEntry_t();
std::unique_ptr< const DilloUrl > Url; /**< Cached Url. Url is used as a primary Key */
char *TypeDet; /**< MIME type string (detected from data) */
std::string TypeDet; /**< MIME type string (detected from data) */
char *TypeHdr; /**< MIME type string as from the HTTP Header */
char *TypeMeta; /**< MIME type string from META HTTP-EQUIV */
char *TypeNorm; /**< MIME type string normalized */
@ -194,7 +194,6 @@ static void Cache_client_dequeue(CacheClient_t *Client)
static void Cache_entry_init(CacheEntry_t *NewEntry, const DilloUrl *Url)
{
NewEntry->Url = a_Url_dup(Url);
NewEntry->TypeDet = NULL;
NewEntry->TypeHdr = NULL;
NewEntry->TypeMeta = NULL;
NewEntry->TypeNorm = NULL;
@ -299,7 +298,6 @@ static void Cache_auth_free(Dlist *auth)
CacheEntry_t::~CacheEntry_t()
{
auto *const entry= this;
dFree(entry->TypeDet);
dFree(entry->TypeHdr);
dFree(entry->TypeMeta);
dFree(entry->TypeNorm);
@ -459,8 +457,13 @@ static void Cache_unref_data(CacheEntry_t *entry)
*/
static const char *Cache_current_content_type(CacheEntry_t *entry)
{
return entry->TypeNorm ? entry->TypeNorm : entry->TypeMeta ? entry->TypeMeta
: entry->TypeHdr ? entry->TypeHdr : entry->TypeDet;
return entry->TypeNorm
? entry->TypeNorm
: entry->TypeMeta
? entry->TypeMeta
: entry->TypeHdr
? entry->TypeHdr
: entry->TypeDet.c_str();
}
/**
@ -516,7 +519,7 @@ const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype,
if (*from == 'm' && charset &&
((!major || !*major) && (!minor || !*minor))) {
/* META only gives charset; use detected MIME type too */
entry->TypeNorm = dStrconcat(entry->TypeDet, ctype, NULL);
entry->TypeNorm = dStrconcat(entry->TypeDet.c_str(), ctype, NULL);
} else if (*from == 'm' &&
!dStrnAsciiCasecmp(ctype, "text/xhtml", 10)) {
/* WORKAROUND: doxygen uses "text/xhtml" in META */