Skip to content

Memory leak with consecutive ftp_nb_fget #10562

Closed

Description

@ndossche

Description

The following code:

<?php

include "ext/ftp/tests/server.inc";

$conn_id = ftp_connect("127.0.0.1", $port) or die("no connection to ftp");

ftp_login($conn_id, 'anonymous', 'IEUser@');

$fout = fopen("test-output.tmp", "w");
$ret = ftp_nb_fget($conn_id, $fout, "fget", FTP_BINARY, 10);
$ret = ftp_nb_fget($conn_id, $fout, "fget", FTP_BINARY, 10);
fclose($fout);

Resulted in this output:

Warning: ftp_nb_fget(): Closing data Connection. in /home/niels/php-src/memleak.php on line 11
[Fri Feb 10 21:53:49 2023]  Script:  '/home/niels/php-src/memleak.php'
/home/niels/php-src/ext/ftp/ftp.c(1631) :  Freeing 0x00007f3176889000 (4108 bytes), script=/home/niels/php-src/memleak.php
=== Total 1 memory leaks detected ===

But I expected this output instead:

Warning: ftp_nb_fget(): Closing data Connection. in /home/niels/php-src/memleak.php on line 11

Seems like the ftp->data pointer gets overwritten before the previous action is done(? not sure, I haven't looked into detail). In any case the pointer is overwritten and the old one isn't freed.
Discovered while developing PR #10525.

There's actually a couple of places where ftp->data could get overwritten I think. Maybe we shouldn't allow doing two non-blocking actions at the same time?

PHP Version

PHP >=8.1

Operating System

Linux

Activity

  1. self-assigned this
    on Jul 6, 2023
  2. added a commit that references this issue on Jul 6, 2023
    95e8b24
  3. added 2 commits that reference this issue on Jul 7, 2023
    c962a96
    4dcb5af
  4. added a commit that references this issue on Jul 7, 2023
    eacfbd9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions