GFileChooser: fix various issues that could lead to a crash

r? @frank-trampe

cc #1640 (for the second part, at least).
Here is why it crashed: `hmax` was always set to zero hence if you had more than 20 entries in your history (the "alloc ahead" constant) it would starting overrunning the heap memory (cc @jtanx).  
I also confirmed that the ptr is NULL at the beginning of the function so that we're not reallocating uninitialized memory.