From: Erich Stamberger Date: Wed, 3 Jul 1996 11:42:16 +0100 (GMT+0100) Subject: [PG95]: BUGREP/Fix: libpq: Two memory leaks ============================================================================ POSTGRES95 BUG REPORT TEMPLATE ============================================================================ Your name : Erich Stamberger Your email address : eberger@gewi.kfunigraz.ac.at System Configuration - --------------------- Architecture (example: Intel Pentium) : Intel Pentium Operating System (example: Linux 1.3.42 ELF) : Linux 1.2.13 Postgres95 version (example: Postgres95-1.01) : Postgres95-1.01pl2 Compiler used (example: gcc 2.7.0) : gcc 2.7.0 Please enter a FULL description of your problem: - ------------------------------------------------ libpq calls "fe_getauthname()" two times in "fe-connect.c", but doesn't free the buffer allocated by this function. If you know how this problem might be fixed, list the solution below: - --------------------------------------------------------------------- *** fe-connect.c 1996/07/03 07:08:11 1.1 - --- fe-connect.c 1996/07/03 09:55:51 1.3 *************** *** 7,13 **** * * * IDENTIFICATION ! * $Header: /home/postgres/postgres95/src/libpq/RCS/fe-connect.c,v 1.1 1996/07/03 07:08:11 postgres Exp $ * *------------------------------------------------------------------------- */ - --- 7,13 ---- * * * IDENTIFICATION ! * $Header: /home/postgres/postgres95/src/libpq/RCS/fe-connect.c,v 1.3 1996/07/03 09:55:51 postgres Exp $ * *------------------------------------------------------------------------- */ *************** *** 109,128 **** } else conn->pgoptions = strdup(pgoptions); ! if (!dbName || dbName[0] == '\0') { ! char errorMessage[ERROR_MSG_LENGTH]; ! if (!(tmp = getenv("PGDATABASE")) && ! !(tmp = fe_getauthname(errorMessage))) { ! sprintf(conn->errorMessage, ! "FATAL: PQsetdb: Unable to determine a database name!\n"); ! /* pqdebug("%s", conn->errorMessage); */ ! conn->dbName = NULL; ! return conn; ! } conn->dbName = strdup(tmp); ! } else ! conn->dbName = strdup(dbName); ! conn->status = connectDB(conn); return conn; } - --- 109,131 ---- } else conn->pgoptions = strdup(pgoptions); ! if (((tmp = dbName) && (dbName[0] != '\0')) || ! ((tmp = getenv("PGDATABASE")))) conn->dbName = strdup(tmp); ! else { ! char errorMessage[ERROR_MSG_LENGTH]; ! if (tmp = fe_getauthname(errorMessage)) { ! conn->dbName = strdup(tmp); ! free(tmp); ! } ! else { ! sprintf(conn->errorMessage, ! "FATAL: PQsetdb: Unable to determine a database name!\n"); ! /* pqdebug("%s", conn->errorMessage); */ ! conn->dbName = NULL; ! return conn; ! } ! } conn->status = connectDB(conn); return conn; } *************** *** 159,166 **** user = fe_getauthname(conn->errorMessage); if (!user) goto connect_errReturn; - - strncpy(startup.database,conn->dbName,sizeof(startup.database)); strncpy(startup.user,user,sizeof(startup.user)); strncpy(startup.tty,conn->pgtty,sizeof(startup.tty)); if (conn->pgoptions) { strncpy(startup.options,conn->pgoptions, sizeof(startup.options)); - --- 162,170 ---- user = fe_getauthname(conn->errorMessage); if (!user) goto connect_errReturn; strncpy(startup.user,user,sizeof(startup.user)); + free(user); + strncpy(startup.database,conn->dbName,sizeof(startup.database)); strncpy(startup.tty,conn->pgtty,sizeof(startup.tty)); if (conn->pgoptions) { strncpy(startup.options,conn->pgoptions, sizeof(startup.options)); Best Regards - --Erich