sftp_new_channel creates an sftp_session without sftp_session->read_packet being initialized.
I work around that doing the following:
s=sftp_new_channel(...);
s->read_packet=calloc(1, sizeof(struct sftp_packet_struct);
s->read_packet->payload = ssh_buffer_new();