From 80f487038c8aaa8d1b0f5e75f582a2048ba7ad6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 8 Jun 2010 17:50:03 +0000 Subject: [PATCH] Notice allocation failures in database fetch. --- org.glite.lbjp-common.db/src/db-mysql.c | 21 +++++++++++++++++---- org.glite.lbjp-common.db/src/db-pg.c | 10 +++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/org.glite.lbjp-common.db/src/db-mysql.c b/org.glite.lbjp-common.db/src/db-mysql.c index 3b525f6..ecec644 100644 --- a/org.glite.lbjp-common.db/src/db-mysql.c +++ b/org.glite.lbjp-common.db/src/db-mysql.c @@ -1007,14 +1007,24 @@ static int FetchRowSimple(glite_lbu_DBContextMysql ctx, MYSQL_RES *result, unsig for (i=0; istmt, binds) != 0) goto failedstmt; diff --git a/org.glite.lbjp-common.db/src/db-pg.c b/org.glite.lbjp-common.db/src/db-pg.c index c0acfc6..1581ac8 100644 --- a/org.glite.lbjp-common.db/src/db-pg.c +++ b/org.glite.lbjp-common.db/src/db-pg.c @@ -348,12 +348,20 @@ int glite_lbu_FetchRowPsql(glite_lbu_Statement stmt_gen, unsigned int maxn, unsi for (i = 0; i < n; i++) { /* sanity check for internal error (NULL when invalid row) */ s = psql_module.PQgetvalue(stmt->res, stmt->row, i) ? : ""; - results[i] = strdup(s); + if ((results[i] = strdup(s)) == NULL) + goto nomem; if (lengths) lengths[i] = strlen(s); } stmt->row++; return n; +nomem: + for (n = i, i = 0; i < n; i++) { + free(results[i]); + results[i] = NULL; + } + set_error(stmt->generic.ctx, ENOMEM, "insufficient memory for field data"); + return -1; } -- 1.8.2.3