The second c_str() call destroys the buffer still being used by the
first c_str() result, leading to many "Invalid read of size N" errors.
IMO, we must instead fix SBuf to make similar violations unlikely, but
there is currently no squid-dev consensus on whether and how to do that.
See "[RFC] Support concurrent SBuf::c_str() calls" thread on squid-dev.
if (calloutContext->error) {
// XXX: prformance regression. c_str() reallocates
- SBuf storeUri(request->storeId());
- StoreEntry *e = storeCreateEntry(storeUri.c_str(), storeUri.c_str(), request->flags, request->method);
+ SBuf storeUriBuf(request->storeId());
+ const char *storeUri = storeUriBuf.c_str();
+ StoreEntry *e = storeCreateEntry(storeUri, storeUri, request->flags, request->method);
#if USE_OPENSSL
if (sslBumpNeeded()) {
// We have to serve an error, so bump the client first.
entry->lock("Ssl::ServerBump");
} else {
// XXX: Performance regression. c_str() reallocates
- SBuf uri(request->effectiveRequestUri());
- entry = storeCreateEntry(uri.c_str(), uri.c_str(), request->flags, request->method);
+ SBuf uriBuf(request->effectiveRequestUri());
+ const char *uri = uriBuf.c_str();
+ entry = storeCreateEntry(uri, uri, request->flags, request->method);
}
// We do not need to be a client because the error contents will be used
// later, but an entry without any client will trim all its contents away.