Browse Source

Perform back off and retry on failed realloc in jansson strbuffer_append_bytes instead of failing

master
ckolivas 10 years ago
parent
commit
71e6043719
  1. 12
      src/jansson-2.6/src/strbuffer.c

12
src/jansson-2.6/src/strbuffer.c

@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "jansson_private.h"
#include "strbuffer.h"
@ -74,6 +75,7 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
{
if(size >= strbuff->size - strbuff->length)
{
int backoff = 1;
size_t new_size;
char *new_value;
@ -86,9 +88,13 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
new_size = max(strbuff->size * STRBUFFER_FACTOR,
strbuff->length + size + 1);
new_value = realloc(strbuff->value, new_size);
if(!new_value)
return -1;
while (42) {
new_value = realloc(strbuff->value, new_size);
if (new_value)
break;
usleep(backoff * 1000);
backoff <<= 1;
}
strbuff->value = new_value;
strbuff->size = new_size;

Loading…
Cancel
Save