From: | Wen Yi <chuxuec(at)outlook(dot)com> |
---|---|
To: | PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Why not use the calloc to replace malloc? |
Date: | 2023-04-23 03:44:32 |
Message-ID: | TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
HI team,
I'm a newbie to the postgres.
When I learn the code of libpq, the achieve of PQmakeEmptyPGresult, cause my curiosity.
The old version code:
PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
{
PGresult *result;
result = (PGresult *) malloc(sizeof(PGresult));
if (!result)
return NULL;
result->ntups = 0;
result->numAttributes = 0;
result->attDescs = NULL;
result->tuples = NULL;
result->tupArrSize = 0;
result->numParameters = 0;
result->paramDescs = NULL;
result->resultStatus = status;
result->cmdStatus[0] = '\0';
result->binary = 0;
result->events = NULL;
result->nEvents = 0;
result->errMsg = NULL;
result->errFields = NULL;
result->errQuery = NULL;
result->null_field[0] = '\0';
result->curBlock = NULL;
result->curOffset = 0;
result->spaceLeft = 0;
result->memorySize = sizeof(PGresult);
/*
.............
*/
return result;
}
My version:
PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
{
PGresult *result;
result = (PGresult *) calloc(sizeof(PGresult));
if (!result)
return NULL;
result->memorySize = sizeof(PGresult);
/*
.............
*/
return result;
}
Why not have a change?I don't know.
I'm a newbie, so I don't think I can commit a patch for postgres, just instead of send mail to ask.
Yours,
Wenyi.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2023-04-23 03:59:37 | Re: Why not use the calloc to replace malloc? |
Previous Message | Tom Lane | 2023-04-22 19:02:54 | Re: SCROLLABLE/UPDATABLE cursor question |