I have uploaded an updated version of the patch:
I found it better to fix the problem in ldif_read_record(), where a similar
situation with EOF was already handled. If the line is not terminated by a
newline character, it is added.
(The previous patch fixed the bug in ldif_countlines() which looks like a
blind shot now.)