* pqAllocCmdQueueEntry * Get a command queue entry for caller to fill. * * If the recycle queue has a free element, that is returned; if not, a * fresh one is allocated. Caller is responsible for adding it to the * command queue (pqAppendCmdQueueEntry) once the struct is filled in, or * releasing the memory (pqRecycleCmdQueueEntry) if an error occurs. * * If allocation fails, sets the er
| 1244 | * If allocation fails, sets the error message and returns NULL. |
| 1245 | */ |
| 1246 | PGcmdQueueEntry * |
| 1247 | pqAllocCmdQueueEntry(PGconn *conn) |
| 1248 | { |
| 1249 | PGcmdQueueEntry *entry; |
| 1250 | |
| 1251 | if (conn->cmd_queue_recycle == NULL) |
| 1252 | { |
| 1253 | entry = (PGcmdQueueEntry *) malloc(sizeof(PGcmdQueueEntry)); |
| 1254 | if (entry == NULL) |
| 1255 | { |
| 1256 | appendPQExpBufferStr(&conn->errorMessage, |
| 1257 | libpq_gettext("out of memory\n")); |
| 1258 | return NULL; |
| 1259 | } |
| 1260 | } |
| 1261 | else |
| 1262 | { |
| 1263 | entry = conn->cmd_queue_recycle; |
| 1264 | conn->cmd_queue_recycle = entry->next; |
| 1265 | } |
| 1266 | entry->next = NULL; |
| 1267 | entry->query = NULL; |
| 1268 | |
| 1269 | return entry; |
| 1270 | } |
| 1271 | |
| 1272 | /* |
| 1273 | * pqAppendCmdQueueEntry |
no test coverage detected