Add custom memory allocation
Thanks to Basile Starynkevitch for the suggestion and initial patch. Thanks to Jonathan Landis and Deron Meranda for showing how this can be utilized for implementing secure memory operations.
This commit is contained in:
16
src/load.c
16
src/load.c
@@ -300,7 +300,7 @@ static void lex_scan_string(lex_t *lex, json_error_t *error)
|
||||
- two \uXXXX escapes (length 12) forming an UTF-16 surrogate pair
|
||||
are converted to 4 bytes
|
||||
*/
|
||||
lex->value.string = malloc(lex->saved_text.length + 1);
|
||||
lex->value.string = jsonp_malloc(lex->saved_text.length + 1);
|
||||
if(!lex->value.string) {
|
||||
/* this is not very nice, since TOKEN_INVALID is returned */
|
||||
goto out;
|
||||
@@ -390,7 +390,7 @@ static void lex_scan_string(lex_t *lex, json_error_t *error)
|
||||
return;
|
||||
|
||||
out:
|
||||
free(lex->value.string);
|
||||
jsonp_free(lex->value.string);
|
||||
}
|
||||
|
||||
#if JSON_INTEGER_IS_LONG_LONG
|
||||
@@ -503,7 +503,7 @@ static int lex_scan(lex_t *lex, json_error_t *error)
|
||||
strbuffer_clear(&lex->saved_text);
|
||||
|
||||
if(lex->token == TOKEN_STRING) {
|
||||
free(lex->value.string);
|
||||
jsonp_free(lex->value.string);
|
||||
lex->value.string = NULL;
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ static int lex_init(lex_t *lex, get_func get, eof_func eof, void *data)
|
||||
static void lex_close(lex_t *lex)
|
||||
{
|
||||
if(lex->token == TOKEN_STRING)
|
||||
free(lex->value.string);
|
||||
jsonp_free(lex->value.string);
|
||||
strbuffer_close(&lex->saved_text);
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ static json_t *parse_object(lex_t *lex, json_error_t *error)
|
||||
|
||||
lex_scan(lex, error);
|
||||
if(lex->token != ':') {
|
||||
free(key);
|
||||
jsonp_free(key);
|
||||
error_set(error, lex, "':' expected");
|
||||
goto error;
|
||||
}
|
||||
@@ -637,18 +637,18 @@ static json_t *parse_object(lex_t *lex, json_error_t *error)
|
||||
lex_scan(lex, error);
|
||||
value = parse_value(lex, error);
|
||||
if(!value) {
|
||||
free(key);
|
||||
jsonp_free(key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(json_object_set_nocheck(object, key, value)) {
|
||||
free(key);
|
||||
jsonp_free(key);
|
||||
json_decref(value);
|
||||
goto error;
|
||||
}
|
||||
|
||||
json_decref(value);
|
||||
free(key);
|
||||
jsonp_free(key);
|
||||
|
||||
lex_scan(lex, error);
|
||||
if(lex->token != ',')
|
||||
|
||||
Reference in New Issue
Block a user