From 172a2f4c66c651bb29610cce72d15061e7c94509 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Thu, 1 Apr 2010 22:27:13 +0200 Subject: [PATCH] Use bstrdup and use a goto for one exit from function. --- bacula/src/cats/myingres.sc | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/bacula/src/cats/myingres.sc b/bacula/src/cats/myingres.sc index 1289f13eed..e632d36999 100644 --- a/bacula/src/cats/myingres.sc +++ b/bacula/src/cats/myingres.sc @@ -31,24 +31,23 @@ short INGgetCols(const char *query) memset(sqlda, 0, (IISQDA_HEAD_SIZE + (number * IISQDA_VAR_SIZE))); sqlda->sqln = number; - - stmt = (char*)malloc(strlen(stmt)+1); - bstrncpy(stmt,stmt,strlen(stmt)+1); + + stmt = bstrdup(query); EXEC SQL PREPARE s1 from :stmt; if (INGcheck() < 0) { - free(stmt); - free(sqlda); - return -1; + number = -1; + goto bail_out; } EXEC SQL DESCRIBE s1 into :sqlda; if (INGcheck() < 0) { - free(stmt); - free(sqlda); - return -1; + number = -1; + goto bail_out; } number = sqlda->sqld; + +bail_out: free(stmt); free(sqlda); return number; @@ -68,8 +67,7 @@ static inline IISQLDA *INGgetDescriptor(short numCols, const char *query) sqlda->sqln = numCols; - stmt = (char *)malloc(strlen(stmt)+1); - bstrncpy(stmt,stmt,strlen(stmt)+1); + stmt = bstrdup(query); EXEC SQL PREPARE s2 INTO :sqlda FROM :stmt; @@ -447,8 +445,7 @@ int INGexec(INGconn *conn, const char *query) char *stmt; EXEC SQL END DECLARE SECTION; - stmt = (char *)malloc(strlen(query)+1); - bstrncpy(stmt,query,strlen(query)+1); + stmt = bstrdup(query); rowcount = -1; EXEC SQL EXECUTE IMMEDIATE :stmt; @@ -570,7 +567,7 @@ char *INGerrorMessage(const INGconn *conn) EXEC SQL END DECLARE SECTION; EXEC SQL INQUIRE_INGRES(:errbuf = ERRORTEXT); - memcpy(conn->msg,&errbuf,256); + memcpy(conn->msg, &errbuf, 256); return conn->msg; } -- 2.39.5