asprintf returns memory pointer which is from malloc() not zmalloc()
This commit is contained in:
parent
d4d1a59728
commit
20e3f1a3ba
3 changed files with 12 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
AC_INIT([r3], 1.0.0)
|
AC_INIT([r3], 1.0.0)
|
||||||
AC_PREREQ([2.64])
|
AC_PREREQ([2.64])
|
||||||
|
AC_USE_SYSTEM_EXTENSIONS
|
||||||
AC_CONFIG_HEADERS(config.h)
|
AC_CONFIG_HEADERS(config.h)
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
||||||
|
@ -18,9 +19,6 @@ AC_TYPE_SIZE_T
|
||||||
AC_FUNC_MALLOC
|
AC_FUNC_MALLOC
|
||||||
AC_FUNC_REALLOC
|
AC_FUNC_REALLOC
|
||||||
AC_CHECK_FUNCS([gettimeofday memset strchr strdup strndup strstr])
|
AC_CHECK_FUNCS([gettimeofday memset strchr strdup strndup strstr])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*
|
*
|
||||||
* Distributed under terms of the MIT license.
|
* Distributed under terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "config.h"
|
#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 * r3_slug_new(char * path, int path_len) {
|
||||||
r3_slug_t * s = zmalloc(sizeof(r3_slug_t));
|
r3_slug_t * s = zmalloc(sizeof(r3_slug_t));
|
||||||
|
if (!s)
|
||||||
|
return NULL;
|
||||||
s->path = path;
|
s->path = path;
|
||||||
s->path_len = path_len;
|
s->path_len = path_len;
|
||||||
|
|
||||||
|
|
|
@ -100,11 +100,13 @@ START_TEST (test_slug_parse_with_pattern)
|
||||||
{
|
{
|
||||||
char * pattern = "/user/{name:\\d{3}}";
|
char * pattern = "/user/{name:\\d{3}}";
|
||||||
char * errstr = NULL;
|
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);
|
char * out = r3_slug_to_str(s);
|
||||||
|
ck_assert(out);
|
||||||
printf("%s\n",out);
|
printf("%s\n",out);
|
||||||
zfree(out);
|
free(out);
|
||||||
|
|
||||||
r3_slug_free(s);
|
r3_slug_free(s);
|
||||||
}
|
}
|
||||||
|
@ -115,11 +117,13 @@ START_TEST (test_slug_parse_without_pattern)
|
||||||
{
|
{
|
||||||
char * pattern = "/user/{name}";
|
char * pattern = "/user/{name}";
|
||||||
char * errstr = NULL;
|
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);
|
char * out = r3_slug_to_str(s);
|
||||||
|
ck_assert(out);
|
||||||
printf("%s\n",out);
|
printf("%s\n",out);
|
||||||
zfree(out);
|
free(out);
|
||||||
|
|
||||||
r3_slug_free(s);
|
r3_slug_free(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue