[PATCH] Remote FILEIO: newly allocated file descriptors have to be initialized.

Maxim Grigoriev maxim@tensilica.com
Thu Aug 9 23:42:00 GMT 2007


This patch has to be approved before I can commit it.

Extra file descriptor array entries don't get initialized when increasing array size.

On the test case :

#define FILENAME "test"    /* name of a file that exists */

#include <stdio.h>
#include <fcntl.h>

main()
{
    int i;
    printf( "Opening many files...\n" );
    for (i = 0; i < 20; i++) {
        int fd = open(FILENAME, O_RDONLY);
        printf( "(%02d)  Got fd = %d\n", i, fd);
    }
}

we end up wasting more memory space than we need :

Opening many files...
(00)  Got fd = 3
(01)  Got fd = 4
(02)  Got fd = 5
(03)  Got fd = 6
(04)  Got fd = 7
(05)  Got fd = 8
(06)  Got fd = 9
(07)  Got fd = 10
(08)  Got fd = 14
(09)  Got fd = 19
(10)  Got fd = 20
(11)  Got fd = 26
(12)  Got fd = 30
(13)  Got fd = 40
(14)  Got fd = 50
(15)  Got fd = 60
(16)  Got fd = 70
(17)  Got fd = 80
(18)  Got fd = 90
(19)  Got fd = 97

With this fix, it looks better:
Opening many files...
(00)  Got fd = 3
(01)  Got fd = 4
(02)  Got fd = 5
(03)  Got fd = 6
(04)  Got fd = 7
(05)  Got fd = 8
(06)  Got fd = 9
(07)  Got fd = 10
(08)  Got fd = 11
(09)  Got fd = 12
(10)  Got fd = 13
(11)  Got fd = 14
(12)  Got fd = 15
(13)  Got fd = 16
(14)  Got fd = 17
(15)  Got fd = 18
(16)  Got fd = 19
(17)  Got fd = 20
(18)  Got fd = 21
(19)  Got fd = 22

Thanks,
-- Maxim


-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote_fileio_resize_fd_map.diff
Type: text/x-patch
Size: 938 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20070809/019a2a1f/attachment.bin>


More information about the Gdb-patches mailing list