Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Remote FILEIO: newly allocated file descriptors have to be  initialized.
@ 2007-08-09 23:42 Maxim Grigoriev
  2007-08-10  2:40 ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Grigoriev @ 2007-08-09 23:42 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]

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



[-- Attachment #2: remote_fileio_resize_fd_map.diff --]
[-- Type: text/x-patch, Size: 938 bytes --]

2007-08-09  Maxim Grigoriev  <maxim2405@gmail.com>

	* remote-fileio.c (remote_fileio_resize_fd_map): Initialize newly
	allocated file descriptors.

Index: remote-fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-fileio.c,v
retrieving revision 1.24
diff -u -r1.24 remote-fileio.c
--- remote-fileio.c	5 Aug 2007 01:04:31 -0000	1.24
+++ remote-fileio.c	9 Aug 2007 23:14:43 -0000
@@ -70,12 +70,16 @@
 static int
 remote_fileio_resize_fd_map (void)
 {
+  int i = remote_fio_data.fd_map_size;
+
   if (!remote_fio_data.fd_map)
     return remote_fileio_init_fd_map ();
   remote_fio_data.fd_map_size += 10;
   remote_fio_data.fd_map =
     (int *) xrealloc (remote_fio_data.fd_map,
 		      remote_fio_data.fd_map_size * sizeof (int));
+  for (; i < remote_fio_data.fd_map_size; i++)
+    remote_fio_data.fd_map[i] = FIO_FD_INVALID;
   return remote_fio_data.fd_map_size - 10;
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Remote FILEIO: newly allocated file descriptors have to be  initialized.
  2007-08-09 23:42 [PATCH] Remote FILEIO: newly allocated file descriptors have to be initialized Maxim Grigoriev
@ 2007-08-10  2:40 ` Daniel Jacobowitz
  2007-08-10 17:56   ` [commit] " Maxim Grigoriev
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2007-08-10  2:40 UTC (permalink / raw)
  To: Maxim Grigoriev; +Cc: gdb-patches

On Thu, Aug 09, 2007 at 04:42:23PM -0700, Maxim Grigoriev wrote:
> 2007-08-09  Maxim Grigoriev  <maxim2405@gmail.com>
> 
> 	* remote-fileio.c (remote_fileio_resize_fd_map): Initialize newly
> 	allocated file descriptors.

This is OK.  Thanks!

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [commit] Remote FILEIO: newly allocated file descriptors have to  be  initialized.
  2007-08-10  2:40 ` Daniel Jacobowitz
@ 2007-08-10 17:56   ` Maxim Grigoriev
  0 siblings, 0 replies; 3+ messages in thread
From: Maxim Grigoriev @ 2007-08-10 17:56 UTC (permalink / raw)
  To: Maxim Grigoriev, gdb-patches

Daniel Jacobowitz wrote:
> On Thu, Aug 09, 2007 at 04:42:23PM -0700, Maxim Grigoriev wrote:
>   
>> 2007-08-09  Maxim Grigoriev  <maxim2405@gmail.com>
>>
>> 	* remote-fileio.c (remote_fileio_resize_fd_map): Initialize newly
>> 	allocated file descriptors.
>>     
>
> This is OK.  Thanks!
>   
Committed after approval.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-08-10 17:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-09 23:42 [PATCH] Remote FILEIO: newly allocated file descriptors have to be initialized Maxim Grigoriev
2007-08-10  2:40 ` Daniel Jacobowitz
2007-08-10 17:56   ` [commit] " Maxim Grigoriev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox