[erlang-questions] Weird behaviuor of ei_x_free

Frans Schneider schneider@REDACTED
Tue Mar 24 10:09:29 CET 2015


Hi list,

While writing a simple port program in C, I ran in a problem with 
deallocating ei_x_buff results. After a few calls to the port, 
ei_x_new_with_version would crash with a malloc error.
It turned out that when I replace the call

ei_x_free(&result);

with

r = ei_x_free(&result);

the problem is solved.
This is what the code looks like:

static void process_helo(const byte *_buf, int _index_start) {
   ei_x_buff result;

   ei_x_new_with_version(&result);
   ei_x_encode_atom(&result, "ok");
   write_port_msg(result);
   ei_x_free(&result);
}

Could somebody explain what is going on here?

Thanks,

Frans

Some details
Erlang / OTP 17.4 from ESL
gcc (Debian 4.7.2-5) 4.7.2
-g or -O3 flags have no differences
Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64 GNU/Linux



More information about the erlang-questions mailing list