freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Lowden, James K" <LowdenJK AT bernstein.com>
- To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
- Subject: RE: Reusing CS_COMMAND structures
- Date: Thu, 23 May 2002 15:31:04 -0400
> From: Sam Denton [mailto:denton AT wantec.com]
> Sent: May 23, 2002 1:59 PM
>> Is it okay to re-use CS_COMMAND structures: i.e.
>> allocate them once, and then re-use them after
>> ct_results returns something other than CS_SUCCEED?
> Patient: "Doctor, it hurts when I do *this*."
> Doctor: "Well, then, don't do that any more."
Musta been a C doctor. C++ doctors recommend *this, and tell you that
eventually you'll like it.
> In ct_cmd_alloc:
> *cmd = (CS_COMMAND *) malloc(sizeof(CS_COMMAND));
> memset(*cmd,'\0',sizeof(CS_COMMAND));
OK. I think both lines could be replaced by:
*cmd = (CS_COMMAND *) calloc(1, sizeof(CS_COMMAND));
but maybe that wouldn't be any more efficient.
> In ct_command:
> if (cmd->query) free(cmd->query);
> cmd->query = (char *) malloc(query_len + 1);
Assumes cmd->query will be null if it had been freed earlier.
if (cmd->query) free... is an unnecessary test (in theory), because
according to free(3), "If ptr is NULL, no action occurs." (What does yours
say?)
> In ct_cmd_drop:
> if (cmd) {
> if (cmd->query) free(cmd->query);
> free(cmd);
> }
Doesn't set cmd = NULL; may be freed again later, with disappointing
results.
> In ct_dynamic:
> if (cmd->query) free(cmd->query);
> cmd->query = (char *) malloc(query_len + 1);
Same caveats as in ct_command.
NetBSD uses /etc/malloc.conf to help debug malloc issues. Maybe your system
has something similar. Might turn something up.
Regards,
--jkl
-
Reusing CS_COMMAND structures,
David Nahman, 05/22/2002
- <Possible follow-up(s)>
- Re: Reusing CS_COMMAND structures, Michael Peppler, 05/23/2002
- RE: Reusing CS_COMMAND structures, Sam Denton, 05/23/2002
- RE: Reusing CS_COMMAND structures, Lowden, James K, 05/23/2002
Archive powered by MHonArc 2.6.24.