Hi all,<br><br><font><font>Has anyone used rabbitmq-c with high availability configuration?<br><br></font></font>I
am stuck with a memory corruption when using rabbitmq-c with high
availability configuration in my own code (the crash is not in librabbitmq). For HA, since the nodes names have to be
taken from a config file, I have implemented the following way of
getting the key value params.<br>
<br><br><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font> std::map<std::string, std::vector<std::string> >ha_map;</font></span></font></font></font></font></font></font></font></font></font></font></font><br><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font> // Load the map here. Typical values:<br></font></span></font></font></font></font></font></font></font></font></font></font></font><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font> // x-ha-policy<font face="tahoma,sans-serif"> - </font>nodes<font face="tahoma,sans-serif">;</font> x-ha-policy-params<font face="tahoma,sans-serif"> - </font>rabbit@centos,rabbit@centos<br><br></font></span></font></font></font></font></font></font></font></font></font></font></font><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font> amqp_table_t table;<br></font></span></font></font></font></font></font></font></font></font></font></font></font></font></span></font></font></font></font></font></font></font></font></font></font></font> std::vector<amqp_field_value_<wbr>t_ *> array_ptrs;<br>
<br> memset(&table, 0, sizeof(table));<br> table.num_entries = ha_map.size();<br> if (table.num_entries)<br> table.entries = (amqp_table_entry_t *) calloc(1, sizeof(amqp_table_entry_t) * table.num_entries);<br>
int i = 0;<br><br> std::map<std::string, std::vector<std::string> >::const_iterator it;<br> for (it = ha_map.begin(); it != ha_map.end(); it++, i++) {<br> table.entries[i].key.len = (*it).first.size();<br>
table.entries[i].key.bytes = (void *) (*it).first.c_str();<br><br> if ((*it).second.size() == 1) {<br> table.entries[i].value.kind = AMQP_FIELD_KIND_UTF8;<br> table.entries[i].value.value.<wbr>bytes.len = (*it).second[0].size();<br>
table.entries[i].value.value.<wbr>bytes.bytes = (void *) (*it).second[0].c_str();<br><br> } else if ((*it).second.size() > 1) {<br> table.entries[i].value.kind = AMQP_FIELD_KIND_ARRAY;<br> table.entries[i].value.value.<wbr>array.num_entries = (*it).second.size();<br>
amqp_field_value_t *f = (amqp_field_value_t_ *) malloc(sizeof(amqp_field_<wbr>value_t_) * (*it).second.size());<br> array_ptrs.push_back(f);<br> table.entries[i].value.value.<wbr>array.entries = f;<br> LogInfo(("Before pointer: %p", table.entries[i].value.value.<wbr>array.entries));<br>
for (size_t j = 0; j < (*it).second.size(); j++) {<br> table.entries[i].value.value.<wbr>array.entries[j].kind = AMQP_FIELD_KIND_UTF8;<br> table.entries[i].value.value.<wbr>array.entries[j].value.bytes.<wbr>len = (*it).second[j].size();<br>
table.entries[i].value.value.<wbr>array.entries[j].value.bytes.<wbr>bytes = (void *) (*it).second[j].c_str();<br> }<br> LogInfo(("Before1 pointer: %p", table.entries[i].value.value.<wbr>array.entries));<br>
}<br> }<br><br> amqp_queue_declare_ok_t *r =<br> amqp_queue_declare(m_conn, m_channel, amqp_cstring_bytes(m_queue.c_<wbr>str()), 0, 1, 0, 0, table);<br><br> for (size_t i = 0; i < array_ptrs.size(); i++) {<br>
free(array_ptrs[i]);<br> }<br> free(table.entries);<br><br><font><font face="tahoma,sans-serif">This works perfectly fine. But the <font>crash happens when I <font>replace<br></font></font></font></font><br>
<font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font><font face="tahoma,sans-serif"><font><font><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font> for (size_t i = 0; i < array_ptrs.size(); i++) {<br>
free(array_ptrs[i]);<br> }<br></font><br></span></font></font></font></font></font></font></font></font></font></font></font></font></span></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></span></font></font></font></font></font></font></font></font></font></font></font><font><font face="tahoma,sans-serif">with<br>
</font></font><font><span style="font-family:courier new,monospace"> for (int k = 0; <font>k</font> < table.num_entries; k++) {<br></span></font><font><span style="font-family:courier new,monospace"><font><font face="tahoma,sans-serif"><font><font><font><font><font><font><font><font><font><span style="font-family:courier new,monospace"><font> LogInfo(("After pointer: %p", table.entries[i].value.value.<wbr>array.entries));<br></font></span></font></font></font></font></font></font></font></font></font></font></font></span></font><b> free(table.entries[k].value.<wbr>value.array.entries);</b><br> }<br><br>
<font>The "After pointer:" is never the same as "Before pointer:". What wrong am I <font>doing here?</font></font><br><br><font>Thanks,<br><font>Arun<br><br>PS: I'm using the following diagnostic log library: https://github.com/visionofarun/CPPLogger<br></font></font>