loci: remove a malloc/free from parsing of_match_t
The code was allocating an of_wire_buffer_t on the heap (through some
indirection) and then immediately freeing it. We can just use the parent
object's wire buffer instead.
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index 3c25807..ee87d0d 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -1453,9 +1453,7 @@
elif m_type == "of_match_t":
out.write("""
LOCI_ASSERT(cur_len + abs_offset <= WBUF_CURRENT_BYTES(wbuf));
- match_octets.bytes = cur_len;
- match_octets.data = OF_OBJECT_BUFFER_INDEX(obj, offset);
- OF_TRY(of_match_deserialize(ver, %(m_name)s, &match_octets));
+ OF_TRY(of_match_deserialize(ver, %(m_name)s, obj, offset, cur_len));
""" % dict(m_name=m_name))
elif m_type == "of_oxm_header_t":
out.write("""
@@ -1504,13 +1502,16 @@
elif m_type == "of_match_t":
out.write("""
- /* Match object */
- OF_TRY(of_match_serialize(ver, %(m_name)s, &match_octets));
- new_len = match_octets.bytes;
- of_wire_buffer_replace_data(wbuf, abs_offset, cur_len,
- match_octets.data, new_len);
- /* Free match serialized octets */
- FREE(match_octets.data);
+ {
+ /* Match object */
+ of_octets_t match_octets;
+ OF_TRY(of_match_serialize(ver, %(m_name)s, &match_octets));
+ new_len = match_octets.bytes;
+ of_wire_buffer_replace_data(wbuf, abs_offset, cur_len,
+ match_octets.data, new_len);
+ /* Free match serialized octets */
+ FREE(match_octets.data);
+ }
""" % dict(m_name=m_name))
else: # Other object type
@@ -1630,12 +1631,6 @@
int new_len, delta; /* For set, need new length and delta */
""")
- # For match, need octet string for set/get
- if m_type == "of_match_t":
- out.write("""\
- of_octets_t match_octets; /* Serialized string for match */
-""")
-
out.write("""
LOCI_ASSERT(%(assert_str)s);
ver = obj->version;