According to https://developer.gnome.org/glib/2.34/glib-IO-Channels.html#g-io-channel-read-line,

    if(buf == NULL) {
        continue;
    }

should be added here.