From 29ac03ef043816b5b11b9105e2a20de2f5dc64f8 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 24 Feb 2011 10:14:06 +0000 Subject: [PATCH] Check for failed allocation in the notice callback --- psycopg/connection_int.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 37fc9b13..fa714f66 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -69,7 +69,15 @@ conn_notice_callback(void *args, const char *message) */ notice = (struct connectionObject_notice *) malloc(sizeof(struct connectionObject_notice)); + if (NULL == notice) { + /* Discard the notice in case of failed allocation. */ + return; + } notice->message = strdup(message); + if (NULL == notice->message) { + free(notice); + return; + } notice->next = self->notice_pending; self->notice_pending = notice; }