diff --git a/21st_century_c/chapter11/dict.c b/21st_century_c/chapter11/dict.c index aa43c97..cd912d3 100644 --- a/21st_century_c/chapter11/dict.c +++ b/21st_century_c/chapter11/dict.c @@ -28,8 +28,10 @@ dictionary *dictionary_new(void) { static void dictionary_add_keyval(dictionary *in, keyval *kv) { in->length++; - in->pairs = realloc(in->pairs, sizeof(keyval*) * in->length); - if(in->pairs != NULL) { + keyval **tmp = realloc(in->pairs, sizeof(keyval*) * in->length); + if(tmp != NULL) { + in->pairs = tmp; + tmp = NULL; in->pairs[in->length-1] = kv; } else { fprintf(stderr, "Out of memory.\n");