- fix mem-leaks with http_curl_callback_ctx
authorMichael Wallner <mike@php.net>
Mon, 13 Jun 2005 16:35:14 +0000 (16:35 +0000)
committerMichael Wallner <mike@php.net>
Mon, 13 Jun 2005 16:35:14 +0000 (16:35 +0000)
- need to sort out curl_multi_strerror

http.c
http_request_api.c
php_http.h
php_http_request_api.h

diff --git a/http.c b/http.c
index 11c7439429ee52b0b6ed1af1eca8d36721ce4a66..62f86ab011d108cbdb08c042472eb6b5d6180079 100644 (file)
--- a/http.c
+++ b/http.c
@@ -137,6 +137,7 @@ static inline void http_globals_init(zend_http_globals *G)
 #ifdef HTTP_HAVE_CURL
        zend_llist_init(&G->request.copies.strings, sizeof(char *), http_request_data_free_string, 0);
        zend_llist_init(&G->request.copies.slists, sizeof(struct curl_slist *), http_request_data_free_slist, 0);
+       zend_llist_init(&G->request.copies.contexts, sizeof(http_curl_callback_ctx *), http_request_data_free_context, 0);
 #endif
 }
 
index ca91a28cae071e142c99430bbfce41a5ceca5a7b..87d40a01e49e1d47f8c6c335c66a7c25af204c39 100644 (file)
@@ -48,14 +48,6 @@ ZEND_EXTERN_MODULE_GLOBALS(http)
 
 #if LIBCURL_VERSION_NUM < 0x070c00
 #      define curl_easy_strerror(code) HTTP_G(request).error
-#      ifndef curl_multi_strerror
-               static char *curl_multi_strerror(int code)
-               {
-                       char message[256] = {0};
-                       snprintf(message, 255, "Unknown HttpRequestPool error (curl multi code: %d)", code);
-                       return http_request_data_copy(COPY_STRING, message);
-               }
-#endif
 #endif
 
 #define HTTP_CURL_INFO(I) HTTP_CURL_INFO_EX(I, I)
@@ -122,11 +114,6 @@ static size_t http_curl_read_callback(void *, size_t, size_t, void *);
 static int http_curl_progress_callback(void *, double, double, double, double);
 static int http_curl_debug_callback(CURL *, curl_infotype, char *, size_t, void *);
 
-typedef struct {
-       void ***tsrm_ctx;
-       void *data;
-} http_curl_callback_ctx;
-
 #define HTTP_CURL_CALLBACK_DATA(from, type, var) \
        http_curl_callback_ctx *__CTX = (http_curl_callback_ctx *) (from); \
        TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \
@@ -185,6 +172,12 @@ void *_http_request_data_copy(int type, void *data TSRMLS_DC)
                        return data;
                }
 
+               case COPY_CONTEXT:
+               {
+                       zend_llist_add_element(&HTTP_G(request).copies.contexts, &data);
+                       return data;
+               }
+               
                default:
                {
                        return data;
@@ -207,6 +200,13 @@ void _http_request_data_free_slist(void *list)
 }
 /* }}} */
 
+/* {{{ _http_request_data_free_context(http_curl_callback_ctx **) */
+void _http_request_data_free_context(void *context)
+{
+       efree(*((http_curl_callback_ctx **) context));
+}
+/* }}} */
+
 /* {{{ http_request_body *http_request_body_new() */
 PHP_HTTP_API http_request_body *_http_request_body_new(TSRMLS_D)
 {
@@ -1073,7 +1073,7 @@ static http_curl_callback_ctx *_http_curl_callback_data(void *data TSRMLS_DC)
        http_curl_callback_ctx *ctx = emalloc(sizeof(http_curl_callback_ctx));
        TSRMLS_SET_CTX(ctx->tsrm_ctx);
        ctx->data = data;
-       return ctx;
+       return http_request_data_copy(COPY_CONTEXT, ctx);
 }
 /* }}} */
 
index 49b79e699d466b67ce22e6b951725bd01dbdc905..e64845755ae19a42bcb8de445ae793425f1e0b15 100644 (file)
@@ -64,6 +64,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
                struct _http_globlas_request_copies {
                        zend_llist strings;
                        zend_llist slists;
+                       zend_llist contexts;
                } copies;
 #      if LIBCURL_VERSION_NUM < 0x070c00
                char error[CURL_ERROR_SIZE + 1];
index 4b642e4625d47644f6196ebd3d175e76c6c959da..3a4467876e34a4f3a44c67f3741829eea35aeaa7 100644 (file)
@@ -82,14 +82,22 @@ typedef struct {
        int unfinished;
 } http_request_pool;
 
-#define COPY_STRING    1
-#define        COPY_SLIST      2
+typedef struct {
+       void ***tsrm_ctx;
+       void *data;
+} http_curl_callback_ctx;
+
+#define COPY_STRING            1
+#define        COPY_SLIST              2
+#define COPY_CONTEXT   3
 #define http_request_data_copy(type, data) _http_request_data_copy((type), (data) TSRMLS_CC)
 extern void *_http_request_data_copy(int type, void *data TSRMLS_DC);
 #define http_request_data_free_string _http_request_data_free_string
 extern void _http_request_data_free_string(void *string);
 #define http_request_data_free_slist _http_request_data_free_slist
 extern void _http_request_data_free_slist(void *list);
+#define http_request_data_free_context _http_request_data_free_context
+extern void _http_request_data_free_context(void *context);
 
 #define http_request_pool_responsehandler _http_request_pool_responsehandler
 extern void _http_request_pool_responsehandler(zval **req TSRMLS_DC);