1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

prevent a memory leak of cli structures

(This used to be commit 911c57403b)
This commit is contained in:
Andrew Tridgell 2001-11-27 03:29:20 +00:00
parent 097d466536
commit 701ecfc7a0
2 changed files with 11 additions and 1 deletions

View 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 */

View 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);
}
}