summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dae0b18)
raw | patch | inline | side by side (parent: dae0b18)
author | Florian Forster <octo@noris.net> | |
Tue, 1 Apr 2008 08:40:39 +0000 (10:40 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Tue, 1 Apr 2008 08:40:39 +0000 (10:40 +0200) |
Why guess the size if you can just adapt to whatever comes in? The memory isn't
freed ever, though.
freed ever, though.
src/apache.c | patch | blob | history |
diff --git a/src/apache.c b/src/apache.c
index 280c687feebd79dcbb5c36ed80bce50d3c4ae844..2a7e0b80cc41ef0e0bf912dab58895bb88b8ee56 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
static CURL *curl = NULL;
-#define ABUFFER_SIZE 16384
-static char apache_buffer[ABUFFER_SIZE];
-static int apache_buffer_len = 0;
-static char apache_curl_error[CURL_ERROR_SIZE];
+static char *apache_buffer = NULL;
+static size_t apache_buffer_size = 0;
+static size_t apache_buffer_fill = 0;
+static char apache_curl_error[CURL_ERROR_SIZE];
static const char *config_keys[] =
{
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, void *stream)
+static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb,
+ void *stream)
{
size_t len = size * nmemb;
- if ((apache_buffer_len + len) >= ABUFFER_SIZE)
- {
- len = (ABUFFER_SIZE - 1) - apache_buffer_len;
- }
-
if (len <= 0)
return (len);
- memcpy (apache_buffer + apache_buffer_len, (char *) buf, len);
- apache_buffer_len += len;
- apache_buffer[apache_buffer_len] = '\0';
+ if ((apache_buffer_fill + len) >= apache_buffer_size)
+ {
+ char *temp;
+
+ temp = (char *) realloc (apache_buffer,
+ apache_buffer_fill + len + 1);
+ if (temp == NULL)
+ {
+ ERROR ("apache plugin: realloc failed.");
+ return (0);
+ }
+ apache_buffer = temp;
+ apache_buffer_size = apache_buffer_fill + len + 1;
+ }
+
+ memcpy (apache_buffer + apache_buffer_fill, (char *) buf, len);
+ apache_buffer_fill += len;
+ apache_buffer[apache_buffer_fill] = 0;
return (len);
}
if (url == NULL)
return (-1);
- apache_buffer_len = 0;
+ apache_buffer_fill = 0;
if (curl_easy_perform (curl) != 0)
{
ERROR ("apache: curl_easy_perform failed: %s",
}
}
- apache_buffer_len = 0;
+ apache_buffer_fill = 0;
return (0);
} /* int apache_read */