aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-10-15 13:55:09 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-10-15 13:55:09 +0100
commit293ea2757b49fd5348c14b2fb178a2dcddced1f7 (patch)
treeb165dbb258e887d5167933cdf820e9310eefcc18
parent555b81de0bc69d3b542d05fadb8a5f2b786bc9e0 (diff)
downloadrspamd-293ea2757b49fd5348c14b2fb178a2dcddced1f7.tar.gz
rspamd-293ea2757b49fd5348c14b2fb178a2dcddced1f7.zip
Add comparasion for rcl vs jansson.
Fix some issues in jansson memory management.
-rw-r--r--src/json/dump.c4
-rw-r--r--src/json/strbuffer.c2
-rw-r--r--test/rspamd_rcl_test.c31
3 files changed, 29 insertions, 8 deletions
diff --git a/src/json/dump.c b/src/json/dump.c
index f384760c5..7e4383abe 100644
--- a/src/json/dump.c
+++ b/src/json/dump.c
@@ -143,7 +143,7 @@ do_dump (const json_t * json, uint32_t flags, int depth, dump_func dump, void *d
return -1;
ret = dump (buffer, size, data);
- g_free (buffer);
+ free (buffer);
return ret;
}
@@ -157,7 +157,7 @@ do_dump (const json_t * json, uint32_t flags, int depth, dump_func dump, void *d
return -1;
ret = dump (buffer, size, data);
- g_free (buffer);
+ free (buffer);
return ret;
}
diff --git a/src/json/strbuffer.c b/src/json/strbuffer.c
index 1ae336d3d..3fa1a92da 100644
--- a/src/json/strbuffer.c
+++ b/src/json/strbuffer.c
@@ -75,7 +75,7 @@ strbuffer_append_bytes (strbuffer_t * strbuff, const char *data, int size)
if (strbuff->length + size >= strbuff->size) {
strbuff->size = max (strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1);
- strbuff->value = realloc (strbuff->value, strbuff->size);
+ strbuff->value = g_realloc (strbuff->value, strbuff->size);
if (!strbuff->value)
return -1;
}
diff --git a/test/rspamd_rcl_test.c b/test/rspamd_rcl_test.c
index 2a93169a6..778340890 100644
--- a/test/rspamd_rcl_test.c
+++ b/test/rspamd_rcl_test.c
@@ -21,9 +21,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "../src/config.h"
-#include "../src/rcl/rcl.h"
-#include "../src/main.h"
+#include "config.h"
+#include "rcl/rcl.h"
+#include "main.h"
+#include "json/jansson.h"
#include "tests.h"
const gchar *rcl_test_valid[] = {
@@ -105,6 +106,8 @@ rspamd_rcl_test_func (void)
GError *err = NULL;
struct timespec start, end;
gdouble seconds;
+ json_t *json;
+ json_error_t jerr;
cur = rcl_test_valid;
while (*cur != NULL) {
@@ -162,14 +165,32 @@ rspamd_rcl_test_func (void)
g_assert_no_error (err);
clock_gettime (CLOCK_MONOTONIC, &end);
seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.;
- msg_info ("parsed json in %.4f seconds", seconds);
+ msg_info ("rcl: parsed json in %.4f seconds", seconds);
/* Test config emitting */
clock_gettime (CLOCK_MONOTONIC, &start);
emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_CONFIG);
g_assert (emitted != NULL);
clock_gettime (CLOCK_MONOTONIC, &end);
seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.;
- msg_info ("emitted object in %.4f seconds", seconds);
+ msg_info ("rcl: emitted object in %.4f seconds", seconds);
rspamd_cl_parser_free (parser);
rspamd_cl_obj_unref (obj);
+ g_free (emitted);
+
+ clock_gettime (CLOCK_MONOTONIC, &start);
+ json = json_load_file ("./rcl_test.json", &jerr);
+ g_assert (json != NULL);
+ clock_gettime (CLOCK_MONOTONIC, &end);
+ seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.;
+ msg_info ("jansson: parsed json in %.4f seconds", seconds);
+
+ clock_gettime (CLOCK_MONOTONIC, &start);
+ emitted = json_dumps (json, 0);
+ g_assert (emitted != NULL);
+ clock_gettime (CLOCK_MONOTONIC, &end);
+ seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.;
+ msg_info ("jansson: emitted object in %.4f seconds", seconds);
+
+ //json_decref (json);
+ g_free (emitted);
}