Fix infinite loop when using rpl_malloc()

The rpl_malloc() implementation call malloc(), leading to an infinite
loop when malloc is defined as rpl_malloc. To fix this add an undef
malloc before the rpl_malloc() implementation. To avoid problems with
other calls to malloc() in dfu.c also move the rpl_malloc()
implementation at the end of the file. While at it also put it under
ifdef to avoid a warning when malloc isn't defined and spare a few
byte as rpl_malloc() is then unneeded.