Restructure some code, fix a small bug in dmenu mode.

 * dmenu crashed on no input lines (wrong free)
 * Pass length of lines to menu function.