diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-02-23 00:28:11 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-02-23 00:32:23 +0000 |
| commit | c1715f66fe483ceacda59f8f763d5128bc0f89e7 (patch) | |
| tree | 90e90f4a3de582c481891d8e011f0b12cd81e9b6 /psycopg/connection_int.c | |
| parent | 143dc2e911498b5c9d306b672a4cc7f9a1d438fc (diff) | |
| download | psycopg2-c1715f66fe483ceacda59f8f763d5128bc0f89e7.tar.gz | |
More careful memory management
- Check return value of PyErr_Malloc and set an exception in case of error
- Avoid exposing variables with refcount 0 as connection attributes.
- PyErr_Free guards itself for NULL input
Diffstat (limited to 'psycopg/connection_int.c')
| -rw-r--r-- | psycopg/connection_int.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 882b0ef..37fc9b1 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -984,14 +984,22 @@ conn_set_client_encoding(connectionObject *self, const char *enc) } /* no error, we can proceeed and store the new encoding */ - PyMem_Free(self->encoding); + { + char *tmp = self->encoding; + self->encoding = NULL; + PyMem_Free(tmp); + } if (!(self->encoding = psycopg_strdup(enc, 0))) { res = 1; /* don't call pq_complete_error below */ goto endlock; } /* Store the python codec too. */ - PyMem_Free(self->codec); + { + char *tmp = self->codec; + self->codec = NULL; + PyMem_Free(tmp); + } self->codec = codec; Dprintf("conn_set_client_encoding: set encoding to %s (codec: %s)", |
