aliyun / aliyun-oss-c-sdk

Aliyun OSS SDK for C
MIT License
151 stars 86 forks source link

request_release not reset request before add to requestStackG #100

Open xuhuleon opened 1 year ago

xuhuleon commented 1 year ago

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);
}

}