Skip to content

Commit 1451753

Browse files
committed
Solve memory leaks in fail path of rapid json serializer.
1 parent 631e0bb commit 1451753

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,21 @@ value rapid_json_serial_impl_deserialize_value(const rapidjson::Value *v)
394394

395395
for (rapidjson::Value::ConstValueIterator it = v->Begin(); it != v->End(); ++it)
396396
{
397-
values[index++] = rapid_json_serial_impl_deserialize_value(it);
397+
values[index] = rapid_json_serial_impl_deserialize_value(it);
398+
399+
if (values[index] == NULL)
400+
{
401+
for (size_t iterator = 0; iterator < index; ++iterator)
402+
{
403+
value_type_destroy(values[iterator]);
404+
}
405+
406+
value_destroy(v_array);
407+
408+
return NULL;
409+
}
410+
411+
++index;
398412
}
399413

400414
return v_array;
@@ -423,6 +437,23 @@ value rapid_json_serial_impl_deserialize_value(const rapidjson::Value *v)
423437
rapid_json_serial_impl_deserialize_value(&it->value)
424438
};
425439

440+
if (tupla[0] == NULL || tupla[1] == NULL)
441+
{
442+
if (tupla[0] != NULL)
443+
{
444+
value_type_destroy(tupla[0]);
445+
}
446+
447+
if (tupla[1] != NULL)
448+
{
449+
value_type_destroy(tupla[1]);
450+
}
451+
452+
value_type_destroy(v_map);
453+
454+
return NULL;
455+
}
456+
426457
tuples[index++] = value_create_array(tupla, sizeof(tupla) / sizeof(tupla[0]));
427458
}
428459

0 commit comments

Comments
 (0)