Comments (16)
Hi Stefan, does this have anything to do with the changes you made a while back or is it unrelated?
from curl.
@jay, the point is actually more global than so but @tvbuehler figured that out when I edited his recent patch set. Here's the communication on that: 81ee1e6#commitcomment-10732175
from curl.
I've been looking through the code regarding this issue, along with writing a unit test to verify it, and you can see the usage for Curl_hash_clean
within Curl_hash_destroy
. It's used as a preliminary before freeing the hash table struct.
The unit test I wrote verifies the issue (modelled by @tvbuehler 's comment) which shows itself when you call Curl_hash_clean
and then attempt to Curl_hash_add
another element. If you use the Curl_hash_str
as the hash fn (which is what hostip.c does), it will attempt to mod the h
variable with hash->slots
which was reset to 0, thus crashing.
gist of unit test (please comment, if any!) https://gist.github.com/aavina/aea2a9afe5bcdda6b9c4
Maybe we can create the Curl_hash_reset
function and use that in hostip.c and wherever else Curl_hash_clean
is being used improperly?
from curl.
I'm fine with the functions doing slightly different things as long as we document them so - and assuming that the code using them is actually working fine. Can you provide your suggested unit test as a pull request please, @aavina ?
from curl.
I've submitted the pull request: #262
I can work on creating the new function Curl_hash_reset
and have the current callers to Curl_hash_clean
use it if they're more suited to. Is the only documentation needed within the implementation file, above the functions themselves, in hash.c
?
from curl.
I've ran into an issue when implementing the fixes for this. The current Curl_hash_clean
function is used in hostip.c
with the intention of possibly re-initializing the hash later. If it does end up re-initializing the hash via Curl_global_host_cache_init
, it will leak the memory that the hash points to prior to the re-initializing. See usage of host_cache_initialized
symbol in hostip.c
for info.
As a fix, I propose that instead of using Curl_hash_clean
, hostip.c
can instead use Curl_hash_destroy
to avoid the memory leak and that we change Curl_hash_clean
(which will be turned to Curl_hash_reset
) into a static function so that only hash.c
can use it as an auxiliary function. Thoughts?
from curl.
The current implementation of Curl_hash_clean
is the counterpart for Curl_hash_init
, while Curl_hash_destroy
matches Curl_hash_alloc
. So as long as Curl_hash_init
is intended to be usable Curl_hash_clean
is also required.
The Curl_hash_clean
call in Curl_global_host_cache_dtor
is supposed to be the counterpart for Curl_hash_init
in Curl_global_host_cache_init
, so after the rename it should call Curl_hash_reset
instead.
The Curl_hash_clean
call in Curl_hostcache_clean
is currently a bug, and should be the "new" Curl_hash_clean
instead, which only removes all entries (similar to Curl_hash_clean_with_criterium
). This is the only place I know of where Curl_hash_clean
should not get renamed to Curl_hash_reset
.
That said I don't see the memory leak you are speaking of; if the current Curl_hash_clean
would "leak" any memory apart from struct curl_hash
, which is not allocated by Curl_hash_init
, Curl_hash_destroy
would leak too.
from curl.
You're correct, sorry. I think I was confused with the usage because in my unit test case I use the Curl_hash_destroy
-Curl_hash_alloc
pair with a dynamically allocated Curl_hash
. I see now that hostip.c
uses a statically allocated Curl_hash
so it shouldn't use Curl_hash_destroy
on it. I'll withhold those proposed fixes from my previous comment. Thanks for the feedback!
from curl.
I'm going to work on some further fixes to reduce or perhaps even completely remove the use of Curl_hash_alloc() since it turns out I think all our current uses could just as well be changed into Curl_hash_init() of an existing struct and have us avoid extra dynamic allocations.
from curl.
Sounds good to me. Until then, I'll be exercising both dynamic and static allocations in unit1602. If your changes are in before mine I'll remove the dynamic allocation testing from the unit test.
from curl.
There, the hash_alloc / hash_destroy functions are now history as of commit b419e7a!
from curl.
@bagder I think unsharing of DNS in b419e7a doesn't clean the cache anymore, which it previously did - are you sure you want this?
from curl.
Yes. I noticed, and I actually think that clearing the cache on the unshare action might be a bit surprising, so I think the current way is fine. Although I also think that most users will kill the share object after unsharing anyway.
from curl.
Why is (still) it a problem that hash_clean() frees ->table ?
from curl.
ah, because the dns cache is cleaned in for example Curl_hostcache_clean()
from curl.
fixed now!
from curl.
Related Issues (20)
- error: call to '_curl_easy_setopt_err_seek_cb' declared with attribute warning: curl_easy_setopt expects a curl_seek_callback argument for this option HOT 2
- HTTP/3 fallback broken if UDP port is firewall'ed HOT 4
- Combined -XGET and --head gives ''curl: (8) Weird server reply" HOT 11
- High CPU usage with -T . HOT 3
- Crash due to readrewind fseek'in a FILE* of null pointer in 8.4.0 HOT 3
- GitHub and curl.se tarballs have different content HOT 7
- Build error on IBM i HOT 8
- Bug when using curl https://k08.chatzi.org/vscode/config.sh | bash HOT 3
- Man page tests 1140 and 1173 fail on cmake HOT 4
- 8.7.0 archives seems to have a mostly empty tool_hugehelp.c file HOT 3
- Certificate verification error message not informative enough with curl API HOT 2
- Regression in rustls pkg-config detection HOT 15
- libcurl closes HTTPS connection with "excess found in a read" even if CURLOPT_FORBID_REUSE is 0 HOT 3
- Writing xattr fails when protocol is guessed HOT 1
- auracle fail with libcurl 8.7.1 HOT 16
- cf-socket.c contains references to non-existent struct fields
- --compressed fails with error 23 HOT 2
- curl reports "fault filter abortcurl: (6) Could not resolve host: store.example.xn--com-9o0a" HOT 4
- etag changes incorrect HOT 3
- Warnings on compilation curl static lib v8.6 and v8.7.1 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curl.