Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Memleaks: ICOL_T

  • Loading branch information...
commit 2f438d4c416f3ce19962c6dc86e95715d347bf1c 1 parent 3a26e30
The X DB authored
View
4 DB/TODO
@@ -1,6 +1,5 @@
GRAND_PLAN:
- 1.) LuaTable (memleaks -> 1 day
3.) Luvit w/ EmbeddedAlchemy -> 2 weeks
4.) EvictedRowSQL_Slave -> 3 weeks
IMPROVEMENTS:
@@ -16,11 +15,10 @@ LUATABLE:
S.) Lua U128 bindings
LUATRIGGER:
- 3.) LUATRIGGER addfunc(isupdate,,,,) delfunc(isupdate,,,,)
- |-> "isupdate" mandatory first argument
4.) add in ability to pass lfunc(col1, 'indexname', 45) -> strings & nums
|-> dont use parseCSLSelect() which can create DynLuaFuncs
5.) UPDATE OVWR can work w/ LUATRIGGERs
+ 6.) nested luatables as args rdbLoad/Save()
REST_API:
1.) push EREDIS down into responsefunctions (better code modularity)
View
7 DB/alsosql.c
@@ -310,6 +310,7 @@ void init_wob(wob_t *wb) {
bzero(wb, sizeof(wob_t)); wb->lim = wb->ofst = -1;
}
void destroy_wob(wob_t *wb) {
+ for (uint32 i = 0; i < wb->nob; i++) releaseIC(&wb->obc[i]);
if (wb->ovar) sdsfree(wb->ovar);
}
@@ -480,7 +481,7 @@ bool sqlSelectInnards(cli *c, sds clist, sds from, sds tlist, sds where,
ret = sqlSelectBinary(c, tmatch, cstar, ics, qcols, &w, &wb,
need_cn, &lfca);
-sel_e: fflush(NULL);
+sel_e:
if (!cstar) resetIndexPosOn(qcols, ics);
destroy_wob(&wb); destroy_check_sql_where_clause(&w);
RELEASE_CS_LS_LIST releaseLFCA(&lfca);
@@ -611,7 +612,7 @@ static bool isUpdatingIndex(int matches, int inds[], icol_t chit[],
int updateInnards(cli *c, int tmatch, sds vallist, sds wclause,
bool fromup, aobj *u_apk) {
//printf("updateInnards: vallist: %s wclause: %s\n", vallist, wclause);
- list *cmatchl = listCreate();
+ CREATE_CS_LS_LIST(0);
list *mvalsl = listCreate(); list *mvlensl = listCreate();
int qcols = parseUpdateColListReply(c, tmatch, vallist, cmatchl,
mvalsl, mvlensl);
@@ -690,6 +691,8 @@ int updateInnards(cli *c, int tmatch, sds vallist, sds wclause,
upc_end:
destroy_wob(&wb); destroy_check_sql_where_clause(&w);
+ for (int i = 0; i < ncols; i++) releaseIC(&chit[i]); // FREED 170
+ release_ics(ics, qcols);
return nsize;
}
static int updateAction(cli *c, sds u_vallist, aobj *u_apk, int u_tmatch) {
View
12 DB/aobj.c
@@ -53,13 +53,12 @@ void initAobj(aobj *a) {
void releaseAobj(void *v) {
aobj *a = (aobj *)v; a->type = COL_TYPE_NONE; a->empty = 1;
if (a->freeme) { free(a->s); a->s = NULL; a->freeme = 0; }
- //if (a->ic) { destroyIC(a->ic); a->ic = NULL; } //TODO
+ if (a->ic) { destroyIC(a->ic); a->ic = NULL; }
}
void destroyAobj(void *v) { releaseAobj(v); free(v); }
void initAobjZeroNum(aobj *a, uchar ctype) {
- initAobj(a);
- a->i = 0; a->l = 0; a->x = 0; a->type = a->enc = ctype; a->empty = 0;
+ initAobj(a); a->type = a->enc = ctype; a->empty = 0;
}
bool initAobjInt(aobj *a, ulong l) {
initAobjZeroNum(a, COL_TYPE_INT); a->i = l; return 1;
@@ -162,6 +161,9 @@ void aobjClone(aobj *dest, aobj *src) {
memcpy(dest->s, src->s, src->len);
dest->freeme = 1;
}
+ if (src->ic) {
+ dest->ic = (icol_t *)malloc(sizeof(icol_t)); cloneIC(dest->ic, src->ic);
+ }
}
aobj *cloneAobj(aobj *a) {
aobj *na = (aobj *)malloc(sizeof(aobj)); aobjClone(na, a); return na;
@@ -441,8 +443,10 @@ void dumpAobj(printer *prn, aobj *a) {
} else if (C_IS_C(a->type)) {
if (a->empty) { (*prn)("\tCNAME aobj: EMPTY\n"); return; }
memcpyAobjStoDumpBuf(a);
- (*prn)("\tCNAME aobj: mt: %d -> (%s) cmatch: %d\n",
+ (*prn)("\tCNAME aobj: mt: %d -> (%s) cmatch: %d",
a->empty, DumpBuf, a->i);
+ if (a->ic) { (*prn)(" ic: "); dumpIC(prn, a->ic); }
+ else (*prn)("\n");
} else if (C_IS_I(a->type) || C_IS_P(a->type)) {
char *name = C_IS_I(a->type) ? "INT" : "FUNC";
if (a->enc == COL_TYPE_INT || a->enc == COL_TYPE_FUNC) {
View
65 DB/colparse.c
@@ -64,16 +64,39 @@ char *Ignore_KW[] = {"PRIMARY", "CONSTRAINT", "UNIQUE", "KEY", "FOREIGN"};
int Ignore_KW_lens[] = { 7, 10, 6, 3, 7};
uint32 Num_Ignore_KW = 5;
+// ICOL_T ICOL_T ICOL_T ICOL_T ICOL_T ICOL_T ICOL_T ICOL_T ICOL_T ICOL_T
+void cloneIC(icol_t *dic, icol_t *sic) {
+ bzero(dic, sizeof(icol_t));
+ dic->cmatch = sic->cmatch;
+ dic->nlo = sic->nlo;
+ //printf("cloneIC: cmatch: %d nlo: %d\n", dic->cmatch, dic->nlo);
+ if (dic->nlo) {
+ dic->lo = malloc(sizeof(sds) * dic->nlo); // FREE 146
+ for (uint32 j = 0; j < dic->nlo; j++) {
+ dic->lo[j] = sdsdup(sic->lo[j]);
+ }
+ }
+}
+void releaseIC(icol_t *ic) {
+ if (ic->nlo) {
+ for (uint32 j = 0; j < ic->nlo; j++) sdsfree(ic->lo[j]);
+ free(ic->lo); // FREE 146
+ }
+}
+void destroyIC (icol_t *ic) { if (ic) { releaseIC(ic); free(ic); } }
+void v_destroyIC(void *v) { destroyIC((icol_t *)v); }
+
// HELPERS HELPERS HELPERS HELPERS HELPERS HELPERS HELPERS HELPERS HELPERS
void init_ics(icol_t *ics, list *cmatchl) {
int ncm = 0;
listIter *lic = listGetIterator(cmatchl, AL_START_HEAD); listNode *lnc;
while((lnc = listNext(lic))) {
- icol_t *ic = lnc->value;
- memcpy(&ics[ncm], ic, sizeof(icol_t)); ncm++;
- } listReleaseIterator(lic);
- //TODO destroy the malloc'ed icol[]s (but not the els of "lo")
- //TODO cloneLo() is the right choice here (& then destroy twice)
+ icol_t *ic = lnc->value;
+ cloneIC(&ics[ncm], ic); ncm++;
+ } listReleaseIterator(lic);
+}
+void release_ics(icol_t *ics, int ncols) {
+ for (int i = 0; i < ncols; i++) releaseIC(&ics[i]);
}
void init_mvals_mvlens(char **mvals, list *mvalsl,
uint32 *mvlens, list *mvlensl) {
@@ -87,16 +110,7 @@ void init_mvals_mvlens(char **mvals, list *mvalsl,
mvlens[ncm] = (uint32)(long)lnc->value; ncm++;
} listReleaseIterator(lic);
}
-void cloneIC(icol_t *dic, icol_t *sic) {
- dic->cmatch = sic->cmatch;
- dic->nlo = sic->nlo;
- if (dic->nlo) {
- dic->lo = malloc(sizeof(sds) * dic->nlo); // FREE 146
- for (uint32 j = 0; j < dic->nlo; j++) {
- dic->lo[j] = sdsdup(sic->lo[j]);
- }
- }
-}
+
// CURSORS CURSORS CURSORS CURSORS CURSORS CURSORS CURSORS CURSORS
/* set "OFFSET var" for next cursor iteration */
void incrOffsetVar(redisClient *c, wob_t *wb, long incr) {
@@ -283,9 +297,8 @@ int deserialiseJTA(uchar *x) {
printf("parseSelCol MISS -> ADD COL: %s tcols: %d\n", \
rt->tcnames[rt->tcols - 1], rt->tcols - 1);
-void luasellistRelease(list *ls) {
- if (!ls) return; listRelease(ls);
-}
+void luasellistRelease(list *ls) { if (ls) listRelease(ls); }
+
static bool parseSelCol(int tmatch, char *cname, int clen,
list *cs, list *ls, int *qcols, bool *cstar,
bool exact, bool isi) {
@@ -388,6 +401,7 @@ static bool parseJCols(cli *c, char *y, int len,
}
jc_t *jc = malloc(sizeof(jc_t));
jc->t = tmatch; jc->c = ic.cmatch; jc->jan = jan;
+ releaseIC(&ic);
listAddNodeTail(js, jc);
INCR(*qcols);
return 1;
@@ -531,7 +545,7 @@ uchar getExprType(char *pred, int plen) {
int parseExpr(cli *c, int tmatch, int cmatch, char *val, uint32 vlen, ue_t *ue){
uint32 i;
uchar ctype = Tbl[tmatch].col[cmatch].type;
- if C_IS_O(ctype) return 0;
+ if C_IS_O(ctype) return 0;//releaseIC-not needed
for (i = 0; i < vlen; i++) {
char e = *(val + i);
if (!ISALNUM(e) && e != '_') break;
@@ -631,15 +645,15 @@ bool parseCommaListToAobjs(char *tkn, int tmatch, list *as) {
a = createAobjFromString(tkn, len, COL_TYPE_STRING); //FREEME 126
icol_t ic = find_column_n(tmatch, tkn, len);
if (ic.cmatch != -1) {
- a->ic = (icol_t *)malloc(sizeof(icol_t));
- cloneIC(a->ic, &ic);
- a->i = ic.cmatch; a->type = COL_TYPE_CNAME;
+ a->ic = (icol_t *)malloc(sizeof(icol_t)); cloneIC(a->ic, &ic);
+ a->i = ic.cmatch; a->type = COL_TYPE_CNAME;
} else {
for (int i = 0; i < len; i++) {
char c2 = *(tkn + i); if (!ISALNUM(c2)) return 0;
}
a->type = COL_TYPE_LUAO;
}
+ releaseIC(&ic);
} else if (ISDIGIT(c)) {
sds num = sdsnewlen(tkn, len); // FREE ME 132
if (is_int(num)) {
@@ -650,7 +664,7 @@ bool parseCommaListToAobjs(char *tkn, int tmatch, list *as) {
sdsfree(num); // FREED 132
}
if (!a) return 0;
- //printf("parseCommaListToAobjs: a: "); dumpAobj(printf, a);
+ //printf("parseCommaListToAobjs: a: (%p) ", a); dumpAobj(printf, a);
listAddNodeTail(as, a);
if (!nextc) break;
tkn = nextc + 1;
@@ -718,7 +732,8 @@ static bool checkExprIsFunc(char *expr, lue_t *le, int tmatch) {
sdsfree(tkn);
void dictIcolDestructor(void *privdata, void *val) {
- ((void) privdata); ((void) val); //printf("dictIcolDestructor\n");
+ ((void) privdata); //printf("dictIcolDestructor\n");
+ icol_t *ic = (icol_t *)val; destroyIC(ic);
}
// PROTOTYPES (from redis.c)
unsigned int dictSdsHash(const void *key);
@@ -791,6 +806,7 @@ bool checkOrCr8LFunc(int tmatch, lue_t *le, sds expr, bool cln) {
addCnameToCdict(cname, mic, colD);
}
} //DEBUG_DEEP_PARSE
+ releaseIC(&ic);
sdsfree(cname); // FREE 141
spot = -1;
}
@@ -812,6 +828,7 @@ bool checkOrCr8LFunc(int tmatch, lue_t *le, sds expr, bool cln) {
addCnameToCdict(cname, mic, colD);
}
} //{int i = len; DEBUG_DEEP_PARSE }
+ releaseIC(&ic);
sdsfree(cname); // FREE 142
}
if (nexpr) nexpr = sdscatlen(nexpr, expr + pleq, len - pleq);//SQL= -> Lua==
View
10 DB/colparse.h
@@ -47,7 +47,8 @@ char *parseRowVals(sds vals, char **pk, int *pklen,
int pcols, icol_t *ics, int lncols, bool *ai);
// HELPERS
-void init_ics(icol_t *ics, list *cmatchl);
+void init_ics (icol_t *ics, list *cmatchl);
+void release_ics(icol_t *ics, int ncols);
#define CMATCHS_FROM_CMATCHL \
icol_t ics[cmatchl->len]; init_ics(ics, cmatchl);
@@ -58,9 +59,12 @@ void init_mvals_mvlens(char **mvals, list *mvalsl,
char *mvals [mvalsl->len]; \
uint32 mvlens [mvlensl->len]; \
init_mvals_mvlens(mvals, mvalsl, mvlens, mvlensl); \
- listRelease(cmatchl); listRelease(mvalsl); listRelease(mvlensl);
+ RELEASE_CS_LS_LIST listRelease(mvalsl); listRelease(mvlensl);
-void cloneIC(icol_t *dic, icol_t *sic);
+void cloneIC (icol_t *dic, icol_t *sic);
+void releaseIC (icol_t *ic);
+void destroyIC (icol_t *ic);
+void v_destroyIC(void *v);
// SELECT
bool parseCSLSelect(cli *c, char *tkn,
View
4 DB/common.h
@@ -172,8 +172,8 @@ typedef struct twoint {
SPLICE_128(num) \
(*prn)("DEBUG_U128: high: %llu low: %llu", ubh, ubl); }
-#define CREATE_CS_LS_LIST(lsalso) \
- list *cmatchl = listCreate(); \
+#define CREATE_CS_LS_LIST(lsalso) \
+ list *cmatchl = listCreate(); cmatchl->free = v_destroyIC; \
list *ls = lsalso ? listCreate() : NULL;
#define RELEASE_CS_LS_LIST \
View
11 DB/ddl.c
@@ -267,8 +267,11 @@ static bool checkRepeatCnames(cli *c, int tmatch, sds cname) {
if (!strcasecmp(cname, "LRU")) { addReply(c, shared.col_lru); return 0; }
if (!strcasecmp(cname, "LFU")) { addReply(c, shared.col_lfu); return 0; }
icol_t ic = find_column(tmatch, cname);
- if (ic.cmatch == -1) return 1;
- else { addReply(c, shared.nonuniquecolumns); return 0; }
+ bool ret;
+ if (ic.cmatch == -1) ret = 1;
+ else { addReply(c, shared.nonuniquecolumns); ret = 0; }
+ releaseIC(&ic);
+ return ret;
}
// addColumn(): Used by ALTER TABLE & LRU & HASHABILITY
void addColumn(int tmatch, char *cname, int ctype) {
@@ -353,8 +356,9 @@ void alterCommand(cli *c) {
if (imatch == -1) { addReply(c, shared.alter_sk_no_i); return;}
if (Index[imatch].lru) { addReply(c, shared.alter_sk_no_lru); return;}
if (Index[imatch].lfu) { addReply(c, shared.alter_sk_no_lfu); return;}
-//TODO check that this is not a LUATABLE
+ //TODO check that this is not a LUATABLE
Tbl[tmatch].sk = ic.cmatch;
+ //TODO releaseIC(&ic);
} else {/* altfk */
if (c->argc < 10) { addReply(c, shared.altersyntax); return;}
if (strcasecmp(c->argv[7]->ptr, "REFERENCES")) {
@@ -389,6 +393,7 @@ void alterCommand(cli *c) {
rt->fk_cmatch = ic.cmatch;
rt->fk_otmatch = otmatch;
rt->fk_ocmatch = oic.cmatch;
+ //TODO releaseIC(&ic); releaseIC(&oic);
}
addReply(c, shared.ok);
}
View
2  DB/filter.c
@@ -62,6 +62,7 @@ static void releaseFilterInnards(f_t *flt, bool le) {
if (flt->key) { sdsfree(flt->key); flt->key = NULL; }
if (flt->low) { sdsfree(flt->low); flt->low = NULL; }
if (flt->high) { sdsfree(flt->high); flt->high = NULL; }
+ releaseIC(&flt->ic);
releaseAobj(&flt->akey); releaseAobj(&flt->alow); releaseAobj(&flt->ahigh);
destroyINLlist(&flt->inl);
if (le) releaseLUE(&flt->le);
@@ -140,6 +141,7 @@ uchar *serialiseFLT(f_t *flt) {
uchar *x = (uchar *)&SerialiseFLT_Buf;
memcpy(x, &flt->tmatch, sizeof(int)); x += sizeof(int);
memcpy(x, &flt->ic.cmatch, sizeof(int)); x += sizeof(int);
+ flt->ic.nlo = 0;
//TODO serialise ic.lo
memcpy(x, &flt->jan, sizeof(int)); x += sizeof(int);
uchar ctype = CTYPE_FROM_FLT(flt)
View
76 DB/index.c
@@ -531,8 +531,8 @@ int newIndex(cli *c, sds iname, int tmatch, icol_t ic,
r_tbl_t *rt = &Tbl [tmatch];
r_ind_t *ri = &Index[imatch]; bzero(ri, sizeof(r_ind_t));
ri->name = sdsdup(iname); // FREE 055
- ri->tmatch = tmatch; ri->icol = ic; ri->clist = clist;
- ri->virt = virt; ri->cnstr = cnstr; ri->lru = lru;
+ ri->tmatch = tmatch; cloneIC(&ri->icol, &ic); ri->clist = clist;
+ ri->virt = virt; ri->cnstr = cnstr; ri->lru = lru;
ri->obc = obc; ri->lfu = lfu;
if (fname) ri->fname = sdsdup(fname); // FREE 162
if (iconstrct) ri->iconstrct = sdsdup(iconstrct); // FREE 167
@@ -618,26 +618,26 @@ bool addC2MCI(cli *c, icol_t ic, list *clist) {
static bool ICommit(cli *c, sds iname, sds tname, sds cname,
uchar cnstr, sds obcname, long limit, uchar dtype,
sds fname, sds iconstrct, sds idestrct) {
- DECLARE_ICOL(ic, -1)
+ DECLARE_ICOL(ic, -1) DECLARE_ICOL(obc, -1)
+ bool ret = 0;
list *clist = NULL;
bool prtl = (limit != -1);
int tmatch = find_table(tname);
- if (tmatch == -1) { addReply(c, shared.nonexistenttable); return 0; }
+ if (tmatch == -1) { addReply(c, shared.nonexistenttable); goto icom_end;}
r_tbl_t *rt = &Tbl[tmatch];
- if (rt->dirty) { addReply(c, shared.buildindexdirty); return 0; }
+ if (rt->dirty) { addReply(c, shared.buildindexdirty); goto icom_end;}
if (prtl && !C_IS_NUM(rt->col[0].type)) { // INDEX CURSOR PK -> NUM
- addReply(c, shared.indexcursorerr); return 0;
+ addReply(c, shared.indexcursorerr); goto icom_end;
}
bool new = 1; // Used in Index Cursors
char *nextc = fname ? NULL : strchr(cname, ',');
if (fname) { // NOOP
} else if (nextc) { /* Multiple Column Index */
char *cn = cname;
- if UNIQ(cnstr) {
- //TODO why cant we have 2 UNIQ MCI's on a table?
- if (rt->nmci) { addReply(c, shared.two_uniq_mci); return 0;
+ if UNIQ(cnstr) { //TODO why cant we have 2 UNIQ MCI's on a table?
+ if (rt->nmci) { addReply(c, shared.two_uniq_mci); goto icom_end;
} else if (!C_IS_NUM(rt->col[0].type)) { /* INT & LONG */
- addReply(c, shared.uniq_mci_pk_notint); return 0;
+ addReply(c, shared.uniq_mci_pk_notint); goto icom_end;
}
}
DECLARE_ICOL(oic, -1)
@@ -646,16 +646,19 @@ static bool ICommit(cli *c, sds iname, sds tname, sds cname,
char *end = nextc - 1;
REV_SKIP_SPACES(end)
oic = find_column_n(tmatch, cn, (end + 1 - cn));
- if (!addC2MCI(c, oic, clist)) return 0;
- //TODO releaseIC(oic);
- if (ic.cmatch == -1) cloneIC(&ic, &oic); // 1st col can be index
+ if (!addC2MCI(c, oic, clist)) {
+ releaseIC(&oic); goto icom_end;
+ } else if (ic.cmatch == -1) { // based at 1st col
+ cloneIC(&ic, &oic); releaseIC(&oic);
+ }
nextc++;
SKIP_SPACES(nextc);
cn = nextc;
nextc = strchr(nextc, ',');
if (!nextc) {
oic = find_column(tmatch, cn);
- if (!addC2MCI(c, oic, clist)) return 0;
+ bool r = addC2MCI(c, oic, clist); releaseIC(&oic);
+ if (!r) goto icom_end;
break;
}
}
@@ -664,7 +667,7 @@ static bool ICommit(cli *c, sds iname, sds tname, sds cname,
icol_t *fic = ln->value;
int fcmatch = fic->cmatch;
if (!C_IS_NUM(rt->col[fcmatch].type)) {
- addReply(c, shared.uniq_mci_notint); return 0;
+ addReply(c, shared.uniq_mci_notint); goto icom_end;
}
}
for (int i = 0; i < Num_indx; i++) { /* already indxd? */
@@ -683,9 +686,12 @@ static bool ICommit(cli *c, sds iname, sds tname, sds cname,
if (prtl && !ri->done) {
new = 0;
if (strcmp(ri->name, iname)) {
- addReply(c, shared.indexcursorerr); return 0;
+ addReply(c, shared.indexcursorerr);
+ goto icom_end;
}
- } else { addReply(c, shared.indexedalready); return 0; }
+ } else {
+ addReply(c, shared.indexedalready); goto icom_end;
+ }
}
}
}
@@ -693,51 +699,53 @@ static bool ICommit(cli *c, sds iname, sds tname, sds cname,
} else {
ic = find_column_sds(tmatch, cname);
if (ic.cmatch <= -1) {
- addReply(c, shared.indextargetinvalid); return 0;
+ addReply(c, shared.indextargetinvalid); goto icom_end;
}
if UNIQ(cnstr) {/*NOTE: RESTRICTION: UNIQUE MCI both cols -> NUM */
if ((!C_IS_NUM(rt->col[ic.cmatch].type) && !C_IS_NUM(dtype)) ||
!C_IS_NUM(rt->col[0].type)) {
- addReply(c, shared.uniq_simp_index_nums); return 0;
+ addReply(c, shared.uniq_simp_index_nums); goto icom_end;
}
- }
+ }
for (int i = 0; i < Num_indx; i++) { /* already indxd? */
r_ind_t *ri = &Index[i];
if (ri->name && ri->tmatch == tmatch && !icol_cmp(&ri->icol, &ic)) {
if (prtl && !ri->done) {
new = 0;
if (strcmp(ri->name, iname)) {
- addReply(c, shared.indexcursorerr); return 0;
+ addReply(c, shared.indexcursorerr); goto icom_end;
}
- } else { addReply(c, shared.indexedalready); return 0; }
+ } else { addReply(c, shared.indexedalready); goto icom_end;}
}
}
}
- DECLARE_ICOL(obc, -1)
if (obcname) {
obc = find_column(tmatch, obcname);
- if (obc.cmatch == -1) { addReply(c, shared.indexobcerr); return 0; }
- if (obc.cmatch == 0) { addReply(c, shared.indexobcrpt); return 0; }
+ if (obc.cmatch == -1) { addReply(c, shared.indexobcerr); goto icom_end;}
+ if (obc.cmatch == 0) { addReply(c, shared.indexobcrpt); goto icom_end;}
if (UNIQ(cnstr) || (!icol_cmp(&obc, &ic)) ||
!C_IS_NUM(rt->col[obc.cmatch].type) ||
!C_IS_NUM(rt->col[0].type)) {
- addReply(c, shared.indexobcill); return 0;
+ addReply(c, shared.indexobcill); goto icom_end;
}
}
if (new) {
if ((newIndex(c, iname, tmatch, ic, clist, cnstr, 0, 0, NULL,
obc, prtl, 0, dtype, fname,
- iconstrct, idestrct)) == -1) return 0;
+ iconstrct, idestrct)) == -1) goto icom_end;
}
if (prtl) {
int imatch = find_partial_index(tmatch, ic);
- if (imatch == -1) { addReply(c, shared.indexcursorerr); return 0; }
+ if (imatch == -1) { addReply(c, shared.indexcursorerr); goto icom_end;}
long card = buildNewIndex(c, tmatch, imatch, limit);
- if (card == -1) return 0;
- else { addReplyLongLong(c, (lolo)card); return 1; }
+ if (card == -1) goto icom_end;
+ else { addReplyLongLong(c, (lolo)card); return 1; }
}
- addReply(c, shared.ok);
- return 1;
+ addReply(c, shared.ok); ret = 1;
+
+icom_end:
+ releaseIC(&ic); releaseIC(&obc);
+ return ret;
}
void createIndex(redisClient *c) {
if (c->argc < 6) { addReply(c, shared.index_wrong_nargs); return; }
@@ -915,6 +923,7 @@ void emptyIndex(cli *c, int imatch) {
if (ri->clist) {
if (rt->nmci) rt->nmci--;
listRelease(ri->clist); /* DESTROYED 054 */
+ for (int i = 0; i < ri->nclist; i++) releaseIC(&ri->bclist[i]);
free(ri->bclist); /* FREED 053 */
}
//NOTE: ri->lru & ri->lfu can NOT be dropped, so no need to change rt
@@ -976,7 +985,7 @@ static bool validatePKandOldVal(lua_State *lua, bt *ibtr,
}
return 0;
}
-//TODO tname, cname, ename can be local variables
+//TODO tname, cname, ename, ic -> local variables
static void getTblColElmntFromLua(lua_State *lua, int stack_size,
sds *tname, sds *cname, sds *ename,
int *tmatch, icol_t *ic, int *imatch) {
@@ -994,6 +1003,7 @@ static void getTblColElmntFromLua(lua_State *lua, int stack_size,
ic->lo = malloc(sizeof(sds) * ic->nlo); // FREE 146
ic->lo[0] = sdsdup(*ename);
*imatch = find_index(*tmatch, *ic);
+ releaseIC(ic);
}
int luaAlchemySetIndex(lua_State *lua) {
View
4 DB/luatrigger.c
@@ -91,8 +91,8 @@ luat_t *init_lua_trigger() {
bzero(luat, sizeof(luat_t)); return luat;
}
static void destroy_ltc(ltc_t *ltc) {
+ release_ics(ltc->ics, ltc->ncols); // FREED 176
if (ltc->ics) free (ltc->ics); // FREED 083
- //TODO WALK ics -> destroyIC(ltc->ics[i])
if (ltc->fname) sdsfree(ltc->fname); // FREED 174
}
void destroy_lua_trigger(luat_t *luat) { //printf("destroy_luatrigger\n");
@@ -135,7 +135,7 @@ static bool parseLuatCmd(cli *c, sds cmd, ltc_t *ltc, int tmatch) {
int cm = ic->cmatch;
//NOTE: no support for U128 or index.pos()
if (C_IS_X(rt->col[cm].type) || cm < 0) { ok = 0; break; }
- cloneIC(&ltc->ics[i], ic); i++;
+ cloneIC(&ltc->ics[i], ic); i++; // FREE 176
} listReleaseIterator(li);
}
RELEASE_CS_LS_LIST
View
6 DB/range.c
@@ -125,8 +125,9 @@ static void setRangeQueued(cswc_t *w, wob_t *wb, qr_t *q) {
bzero(q, sizeof(qr_t));
r_ind_t *ri = (w->wf.imatch == -1) ? NULL: &Index[w->wf.imatch];
bool virt = ri ? ri->virt : 0;
- DECLARE_ICOL(ic, -1) if (ri && ri->icol.cmatch) ic = ri->icol;
- DECLARE_ICOL(obc, 0); if (ri && ri->obc.cmatch != -1) obc = ri->obc;
+ DECLARE_ICOL(ic, -1) DECLARE_ICOL(obc, 0)
+ if (ri && ri->icol.cmatch) cloneIC(&ic, &ri->icol);
+ if (ri && ri->obc.cmatch != -1) cloneIC(&obc, &ri->obc);
if (virt) { // NOTE: there is no inner_desc possible (no inner loop)
q->pk_desc = ((wb->nob >= 1) && !wb->asc[0] &&
!icol_cmp(&wb->obc[0], &obc));
@@ -168,6 +169,7 @@ static void setRangeQueued(cswc_t *w, wob_t *wb, qr_t *q) {
q->xth = q->fk_lo && !(w->flist && (wb->ofst != -1));
q->qed = q->fk;
} //dumpQueued(printf, w, wb, q, 1);
+ releaseIC(&ic); releaseIC(&obc);
}
static void setInQueued(cswc_t *w, wob_t *wb, qr_t *q) {
setRangeQueued(w, wb, q); q->pk_lo = q->fk_lo = 0;// LIM OFST -> ALWAYS SORT
View
3  DB/rdb_alsosql.c
@@ -76,6 +76,7 @@ static int saveLtc(FILE *fp, ltc_t *ltc) {
if (rdbSaveLen(fp, ltc->ncols) == -1) return -1;
for (int j = 0; j < ltc->ncols; j++) {
if (rdbSaveLen(fp, ltc->ics[j].cmatch) == -1) return -1;
+ //TODO FIXME: dump ics[j].lo
}
return 0;
}
@@ -383,7 +384,7 @@ bool rdbLoadBT(FILE *fp) { //printf("rdbLoadBT\n");
if (!addC2MCI(NULL, ic, ri->clist)) return 0;
cloneIC(&ri->bclist[i], &ic);
if (!i) cloneIC(&ri->icol, &ic);
- //TODO releaseIC(ic);
+ releaseIC(&ic);
}
}
ri->virt = 0;
View
2  DB/wc.c
@@ -179,7 +179,7 @@ static bool parseOBYcol(cli *c, char **token, int tmatch,
} else { wb->nob++; sdsfree(t2); return 1; }
}
DECLARE_ICOL(ic, -1)
- wb->obt[wb->nob] = tmatch; wb->obc[wb->nob] = ic; // Simple Parse DEFAULT
+ wb->obt[wb->nob] = tmatch; cloneIC(&wb->obc[wb->nob], &ic); // DEFAULT
if (isj) { // JOIN COLUMN [tbl.col]
if ((wb->obt[wb->nob] = find_table_n(t2, join)) == -1) {
addReply(c, shared.join_order_by_tbl); sdsfree(t2); return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.