Changeset: ee41d0879431 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ee41d0879431
Modified Files:
        gdk/gdk_logger.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_profiler.c
Branch: Sep2022
Log Message:

Fix some potential memory leaks + a bit of cleanup.


diffs (101 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1244,7 +1244,7 @@ log_read_transaction(logger *lg)
                GDKdebug = dbg;
 
        if (cands)
-               GDKfree(cands);
+               BBPunfix(cands->batCacheid);
        if (!ok)
                return LOG_EOF;
        return err;
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -276,7 +276,7 @@ MCinitClientRecord(Client c, oid user, b
        }
        c->promptlength = strlen(prompt);
 
-       c->profticks = c->profstmt = NULL;
+       c->profticks = c->profstmt = c->profevents = NULL;
        c->error_row = c->error_fld = c->error_msg = c->error_input = NULL;
        c->sqlprofiler = 0;
        c->wlc_kind = 0;
@@ -478,7 +478,8 @@ MCfreeClient(Client c)
        if( c->profticks){
                BBPunfix(c->profticks->batCacheid);
                BBPunfix(c->profstmt->batCacheid);
-               c->profticks = c->profstmt = NULL;
+               BBPunfix(c->profevents->batCacheid);
+               c->profticks = c->profstmt = c->profevents = NULL;
        }
        if( c->error_row){
                BBPunfix(c->error_row->batCacheid);
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -108,7 +108,7 @@ lognew(struct logbuf *logbuf)
 static inline void
 logdel(struct logbuf *logbuf)
 {
-       free(logbuf->logbuffer);
+       GDKfree(logbuf->logbuffer);
        logbuf->logbuffer = NULL;
 }
 
@@ -142,7 +142,7 @@ logadd(struct logbuf *logbuf, const char
                        logbuf->logcap = (size_t) tmp_len + (size_t) tmp_len/2;
                        if (logbuf->logcap < LOGLEN)
                                logbuf->logcap = LOGLEN;
-                       alloc_buff = realloc(logbuf->logbuffer, logbuf->logcap);
+                       alloc_buff = GDKrealloc(logbuf->logbuffer, 
logbuf->logcap);
                        if (alloc_buff == NULL) {
                                TRC_ERROR(MAL_SERVER, "Profiler JSON buffer 
reallocation failure\n");
                                logdel(logbuf);
@@ -661,7 +661,7 @@ profilerEvent(MalEvent *me, NonMalEvent 
                }
                if (event) {
                        logjsonInternal(event, true);
-                       free(event);
+                       GDKfree(event);
                }
        }
        MT_lock_unset(&mal_profileLock);
@@ -829,15 +829,10 @@ static void
        cntxt->profticks = cntxt->profstmt = cntxt->profevents = NULL;
 }
 
-static BAT *
+static inline BAT *
 TRACEcreate(int tt)
 {
-       BAT *b;
-
-       b = COLnew(0, tt, 1 << 10, TRANSIENT);
-       if (b == NULL)
-               return NULL;
-       return b;
+       return COLnew(0, tt, 1 << 10, TRANSIENT);
 }
 
 static void
@@ -942,8 +937,7 @@ sqlProfilerEvent(Client cntxt, MalBlkPtr
        }
        errors += BUNappend(cntxt->profticks, &pci->ticks, false) != 
GDK_SUCCEED;
        errors += BUNappend(cntxt->profstmt, c, false) != GDK_SUCCEED;
-       if( ev)
-               errors += BUNappend(cntxt->profevents, ev, false) != 
GDK_SUCCEED;
+       errors += BUNappend(cntxt->profevents, ev ? ev : str_nil, false) != 
GDK_SUCCEED;
        if (errors > 0) {
                /* stop profiling if an error occurred */
                cntxt->sqlprofiler = FALSE;
@@ -951,7 +945,7 @@ sqlProfilerEvent(Client cntxt, MalBlkPtr
 
        MT_lock_unset(&mal_profileLock);
        GDKfree(stmt);
-       if(ev) free(ev);
+       GDKfree(ev);
 }
 
 lng
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to