Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request_release not reset request before add to requestStackG #100

Open
xuhuleon opened this issue Feb 10, 2023 · 0 comments
Open

request_release not reset request before add to requestStackG #100

xuhuleon opened this issue Feb 10, 2023 · 0 comments

Comments

@xuhuleon
Copy link

when call aos_request_get, request will be reset to init status.
If we reset request before add to requestStackG, we can release unneed memory.

// related codes:

CURL *aos_request_get()
{
CURL *request = NULL;

apr_thread_mutex_lock(requestStackMutexG);
if (requestStackCountG > 0) {
    request = requestStackG[--requestStackCountG];
}
apr_thread_mutex_unlock(requestStackMutexG);

// If we got one, deinitialize it for re-use
if (request) {
    curl_easy_reset(request);
}
else {
    request = curl_easy_init();
}

return request;

}

void request_release(CURL *request)
{
apr_thread_mutex_lock(requestStackMutexG);

// If the request stack is full, destroy this one
// else put this one at the front of the request stack; we do this because
// we want the most-recently-used curl handle to be re-used on the next
// request, to maximize our chances of re-using a TCP connection before it
// times out
if (requestStackCountG == AOS_REQUEST_STACK_SIZE) {
    apr_thread_mutex_unlock(requestStackMutexG);
    curl_easy_cleanup(request);
}
else {
    requestStackG[requestStackCountG++] = request;
    apr_thread_mutex_unlock(requestStackMutexG);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant