The following simple program (attachment test.c) crashes when libsox is compiled dynamically ( i.e. --with_dyn_default ), e.g. in most Linux distros like Debian/Ubuntu or Fedora and derivatives.
The reason is that the end condition for the for cycle in "sox_find_format" ( from src/formats.c ) is "s_sox_format_fns[f].fn == NULL", a condition which does not occur if "s_sox_format_fns[f].fn" points to an in invalid address. Unfortunately, that's exactly what happens when libsox is compiled dynamically, the searched format is compiled in a plugin and the progam calls libsox more than once: the last ( f = NSTATIC_FORMATS ) "s_sox_format_fns[f].fn" is not NULL and points to the address of the first plugin function, when it was allocated the first time ( which of course is no more a valid address the second time it is allocated ).
A possible solution is in the attached patch: "sox_format_quit" ( from src/formats.c ) set "s_sox_format_fns[NSTATIC_FORMATS].fn" to NULL, so that the for cycle correctly ends if it doesn't find the format, that it was looking for, among those statically compiled. When libsox calls "sox_format_init" again, the addresses in "s_sox_format_fns[f].fn" are all valid again beyond NSTATIC_FORMATS and the function can work properly.
A working patch:
Fixed.