static void avro_schema_free()

in lang/c/src/schema.c [117:215]


static void avro_schema_free(avro_schema_t schema)
{
	if (is_avro_schema(schema)) {
		switch (avro_typeof(schema)) {
		case AVRO_STRING:
		case AVRO_BYTES:
		case AVRO_INT32:
		case AVRO_INT64:
		case AVRO_FLOAT:
		case AVRO_DOUBLE:
		case AVRO_BOOLEAN:
		case AVRO_NULL:
		case AVRO_INVALID:
			/* no memory allocated for primitives */
			return;

		case AVRO_RECORD:{
				struct avro_record_schema_t *record;
				record = avro_schema_to_record(schema);
				avro_str_free(record->name);
				if (record->space) {
					avro_str_free(record->space);
				}
				st_foreach(record->fields, (hash_function_foreach) record_free_foreach,
					   0);
				st_free_table(record->fields_byname);
				st_free_table(record->fields);
				avro_freet(struct avro_record_schema_t, record);
			}
			break;

		case AVRO_ENUM:{
				struct avro_enum_schema_t *enump;
				enump = avro_schema_to_enum(schema);
				avro_str_free(enump->name);
				if (enump->space) {
					avro_str_free(enump->space);
				}
				st_foreach(enump->symbols, (hash_function_foreach) enum_free_foreach,
					   0);
				st_free_table(enump->symbols);
				st_free_table(enump->symbols_byname);
				avro_freet(struct avro_enum_schema_t, enump);
			}
			break;

		case AVRO_FIXED:{
				struct avro_fixed_schema_t *fixed;
				fixed = avro_schema_to_fixed(schema);
				avro_str_free((char *) fixed->name);
				if (fixed->space) {
					avro_str_free((char *) fixed->space);
				}
				avro_freet(struct avro_fixed_schema_t, fixed);
			}
			break;

		case AVRO_MAP:{
				struct avro_map_schema_t *map;
				map = avro_schema_to_map(schema);
				avro_schema_decref(map->values);
				avro_freet(struct avro_map_schema_t, map);
			}
			break;

		case AVRO_ARRAY:{
				struct avro_array_schema_t *array;
				array = avro_schema_to_array(schema);
				avro_schema_decref(array->items);
				avro_freet(struct avro_array_schema_t, array);
			}
			break;
		case AVRO_UNION:{
				struct avro_union_schema_t *unionp;
				unionp = avro_schema_to_union(schema);
				st_foreach(unionp->branches, (hash_function_foreach) union_free_foreach,
					   0);
				st_free_table(unionp->branches);
				st_free_table(unionp->branches_byname);
				avro_freet(struct avro_union_schema_t, unionp);
			}
			break;

		case AVRO_LINK:{
				struct avro_link_schema_t *link;
				link = avro_schema_to_link(schema);
				/* Since we didn't increment the
				 * reference count of the target
				 * schema when we created the link, we
				 * should not decrement the reference
				 * count of the target schema when we
				 * free the link.
				 */
				avro_freet(struct avro_link_schema_t, link);
			}
			break;
		}
	}
}