prevent a memory leak of cli structures
authorAndrew Tridgell <tridge@samba.org>
Tue, 27 Nov 2001 03:29:20 +0000 (03:29 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 27 Nov 2001 03:29:20 +0000 (03:29 +0000)
source/include/client.h
source/libsmb/clientgen.c

index 9dd41313f284002d5b2d8ad5ba4f605c5e5c112b..fde001813d3801d10eb153443a7f67193374a936 100644 (file)
@@ -138,6 +138,10 @@ struct cli_state {
        BOOL (*oplock_handler)(struct cli_state *cli, int fnum, unsigned char level);
 
        BOOL force_dos_errors;
+
+       /* was this structure allocated by cli_initialise? If so, then
+           free in cli_shutdown() */
+       BOOL allocated;
 };
 
 #endif /* _CLIENT_H */
index 0e093888036a69a3479825e4bb0afa05a6e6ea71..610af9cc237378100cacda19f65103aeac6c1b58 100644 (file)
@@ -217,6 +217,7 @@ struct cli_state *cli_initialise(struct cli_state *cli)
        cli->nt_pipe_fnum = 0;
 
        cli->initialised = 1;
+       cli->allocated = alloced_cli;
 
        return cli;
 
@@ -238,6 +239,7 @@ shutdown a client structure
 ****************************************************************************/
 void cli_shutdown(struct cli_state *cli)
 {
+       BOOL allocated;
        SAFE_FREE(cli->outbuf);
        SAFE_FREE(cli->inbuf);
 
@@ -252,7 +254,11 @@ void cli_shutdown(struct cli_state *cli)
 #endif /* WITH_SSL */
        if (cli->fd != -1) 
                close(cli->fd);
-       memset(cli, 0, sizeof(*cli));
+       allocated = cli->allocated;
+       ZERO_STRUCTP(cli);
+       if (allocated) {
+               free(cli);
+       } 
 }