From: Marco van Wieringen Date: Thu, 1 Apr 2010 20:27:13 +0000 (+0200) Subject: Use bstrdup and use a goto for one exit from function. X-Git-Tag: Release-5.0.2~130 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=172a2f4c66c651bb29610cce72d15061e7c94509;p=bacula%2Fbacula Use bstrdup and use a goto for one exit from function. --- 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; }