You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by su...@apache.org on 2017/07/06 15:50:57 UTC
[2/3] incubator-trafodion git commit: fix TRAFODION-2677
fix TRAFODION-2677
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/ecc76bd4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/ecc76bd4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/ecc76bd4
Branch: refs/heads/master
Commit: ecc76bd45282008d7ea45e4bea4090a6d3616bcd
Parents: ee497fe
Author: SuJinpei <87...@qq.com>
Authored: Wed Jul 5 18:10:32 2017 +0800
Committer: SuJinpei <87...@qq.com>
Committed: Wed Jul 5 18:10:32 2017 +0800
----------------------------------------------------------------------
core/conn/odb/src/odb.c | 101 +++++++++++++++----------------------------
1 file changed, 35 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ecc76bd4/core/conn/odb/src/odb.c
----------------------------------------------------------------------
diff --git a/core/conn/odb/src/odb.c b/core/conn/odb/src/odb.c
index 21fab6d..b2c717d 100755
--- a/core/conn/odb/src/odb.c
+++ b/core/conn/odb/src/odb.c
@@ -663,12 +663,9 @@ char nows[20], /* string with date/time in YYYY-MM-DD HH:MM:SS
chsch[64]; /* Set Schema command */
struct ovar *vv=0; /* struct var pointer for the Interpreter */
const char alnum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ; /* look-up tab to generate random strings */
-
-struct OpointerNode /* record allocated pointer for later free */
-{
- void *ptr;
- struct OpointerNode *next;
-} *ptrHead, *ptrTail;
+void **globalPointers = NULL; /* save pointers to buffers which may shared by many thread and length determined at run time */
+int nGlobalPointers = 0; /* number of pointers in globalPointers */
+int naGlobalPointers = 0; /* number of globalPointers allocated chunk */
/* Functions prototypes */
static void Oerr(int eid, int tid, unsigned int line, SQLHANDLE Ohandle, SQLSMALLINT Otype);
@@ -745,8 +742,7 @@ static char *parsehdfs(int eid, char *hdfs);
unsigned long tspdiff ( struct timespec *start, struct timespec *end ) ;
#endif
static int ucs2toutf8 ( SQLCHAR *str, SQLLEN *len, SQLULEN bs, int bu2 ) ;
-static int appendGlobalPointerChain(void *ptr);
-static void freeGlobalPointerChain();
+static void addGlobalPointer(void *ptr);
int main(int ac, char *av[])
{
@@ -4329,7 +4325,12 @@ static void gclean(void)
}
}
(void)SQLFreeHandle(SQL_HANDLE_ENV, Oenv);
- freeGlobalPointerChain();
+
+ for (int i = 0; i < nGlobalPointers; ++i) /* free globalPointers buffer */
+ {
+ free(globalPointers[i]);
+ }
+ free(globalPointers);
}
/* cancel: executed in interactive mode when ^C is pressed:
@@ -4884,20 +4885,17 @@ static void etabadd(char type, char *run, int id)
fprintf(stderr, "odb [etabadd(%d)] - Error: missing \'tgt\' operator\n", __LINE__ );
goto etabadd_exit;
}
- else
- {
- /* Allocate new buf to save Catalog/Schema/Object */
- char *ptrCSO = (char *)malloc(strlen(etab[no].tgt) + 1);
- strcpy(ptrCSO, etab[no].tgt);
- if (appendGlobalPointerChain(ptrCSO))
- {
- goto etabadd_exit;
- }
-
- /* Split Catalog/Schema/Object */
- splitcso(ptrCSO, etab[no].Ocso, 1);
- if (f & 04000000000) /* no catalog as null */
- etab[no].Ocso[0] = '\0';
+ else
+ {
+ /* Allocate new buf to save Catalog/Schema/Table */
+ char *ptrCST = (char *)malloc(strlen(etab[no].tgt) + 1);
+ strcpy(ptrCST, etab[no].tgt);
+ addGlobalPointer(ptrCST);
+
+ /* Split Catalog/Schema/Table */
+ splitcso(ptrCST, etab[no].Ocso, 1);
+ if (f & 04000000000) /* no catalog as null */
+ etab[no].Ocso[0] = '\0';
}
if ( etab[no].flg2 & 0400000000 ) { /* user defined iobuff */
if ( !etab[no].iobuff ) { /* iobuff set to zero */
@@ -13956,50 +13954,21 @@ static int ucs2toutf8 ( SQLCHAR *str, SQLLEN *len, SQLULEN bs, int bu2 )
return(ret);
}
-/* appendGlobalPointerChain:
- * append ptr to global variable ptrHead list.
- *
- * return: 0 on success, -1 on fail.
- */
-static int appendGlobalPointerChain(void *ptr)
-{
- struct OpointerNode *pnew = (struct OpointerNode *)calloc(1, sizeof(struct OpointerNode));
- if (pnew == NULL)
- {
- fprintf(stderr, "odb [main(%d)] - Error allocating memory for %s: [%d] %s\n",
- __LINE__, __FILE__, errno, strerror(errno));
- return -1;
- }
- pnew->ptr = ptr;
- if (ptrHead == NULL)
- {
- ptrHead = ptrTail = pnew;
- }
- else
- {
- ptrTail->next = pnew;
- ptrTail = pnew;
- }
- return 0;
-}
-
-/* freeGlobalPointerChain:
- * free global ptrHead list.
- */
-static void freeGlobalPointerChain()
+/* addGlobalPointer:
+* add ptr globalPointers buffer
+*
+* return: no return, exit on error
+*/
+static void addGlobalPointer(void *ptr)
{
- struct OpointerNode *pNext = NULL;
- while (ptrHead)
- {
- pNext = ptrHead->next;
- if (ptrHead->ptr)
- {
- free(ptrHead->ptr);
- }
- free(ptrHead);
- ptrHead = pNext;
- }
- ptrTail = NULL;
+ if (nGlobalPointers >= (naGlobalPointers * ETAB_CHUNK - 2)) { /* need new memory */
+ if ((globalPointers = realloc(globalPointers, ++naGlobalPointers*ETAB_CHUNK * sizeof(void *))) == (void *)NULL) {
+ fprintf(stderr, "%s [etabnew(%d)] - Error allocating %dth block of etab[] memory: [%d] %s\n",
+ __FILE__, __LINE__, naGlobalPointers, errno, strerror(errno));
+ exit(EX_OSERR);
+ }
+ }
+ globalPointers[nGlobalPointers++] = ptr;
}
/* usagexit: