From 20e3f1a3ba35548cd2494801592eafd1a438f79d Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 05:48:27 +0800 Subject: [PATCH] asprintf returns memory pointer which is from malloc() not zmalloc() --- configure.ac | 4 +--- src/slug.c | 3 +++ tests/check_slug.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 7158f20..5d4c10b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,6 @@ AC_INIT([r3], 1.0.0) AC_PREREQ([2.64]) +AC_USE_SYSTEM_EXTENSIONS AC_CONFIG_HEADERS(config.h) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign subdir-objects]) @@ -18,9 +19,6 @@ AC_TYPE_SIZE_T AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([gettimeofday memset strchr strdup strndup strstr]) - - - PKG_PROG_PKG_CONFIG diff --git a/src/slug.c b/src/slug.c index fdd039a..d19df8a 100644 --- a/src/slug.c +++ b/src/slug.c @@ -4,6 +4,7 @@ * * Distributed under terms of the MIT license. */ +#include #include #include #include "config.h" @@ -19,6 +20,8 @@ inline int contains_slug_char(const char * str) { r3_slug_t * r3_slug_new(char * path, int path_len) { r3_slug_t * s = zmalloc(sizeof(r3_slug_t)); + if (!s) + return NULL; s->path = path; s->path_len = path_len; diff --git a/tests/check_slug.c b/tests/check_slug.c index bae4d42..aeb0544 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -100,11 +100,13 @@ START_TEST (test_slug_parse_with_pattern) { char * pattern = "/user/{name:\\d{3}}"; char * errstr = NULL; - r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + const r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + ck_assert(s); char * out = r3_slug_to_str(s); + ck_assert(out); printf("%s\n",out); - zfree(out); + free(out); r3_slug_free(s); } @@ -115,11 +117,13 @@ START_TEST (test_slug_parse_without_pattern) { char * pattern = "/user/{name}"; char * errstr = NULL; - r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + const r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + ck_assert(s); char * out = r3_slug_to_str(s); + ck_assert(out); printf("%s\n",out); - zfree(out); + free(out); r3_slug_free(s); }