[MPlayer-dev-eng] [PATCHv2 7/8] stream ftp: Allocate command buffer on-heap

Alexander Strasser eclipse7 at gmx.net
Mon Nov 19 22:24:18 CET 2012


Alexander Strasser wrote:
> Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
> ---
>  stream/stream_ftp.c | 44 +++++++++++++++++++++++++-------------------
>  1 file changed, 25 insertions(+), 19 deletions(-)
> 
[...]
> @@ -434,8 +439,9 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
>  
>    // Allocate buffers
>    p->buf = malloc(BUFSIZE);
> +  p->cmd_buf = malloc(CMD_BUFSIZE);

  It occurred to me today that I was probably too conservative with
this patch.

  If we replace above allocation with something along the lines of:

  p->cmd_buf_size = 5 + FFMIN(strlen(p->filename)+1, 1<<15); // "RETR <file>"
  p->cmd_buf = malloc(p->cmd_buf_size);

  /* additionally change all occurrences of CMD_BUFSIZE to ->cmd_buf_size and
   * get correct off-by-one snprintf size arguments (this time it will matter)
   */

We can drop patch 8/8 and will still have a more desirable solution:

  - Don't allocate 8k every time we are opening a file via ftp
  - If we are opening a filename longer than ~8k it will still work

[...]

  Alexander


More information about the MPlayer-dev-eng mailing list