diff --git a/pyext/Makefile.am b/pyext/Makefile.am index ffd70ccd2..14de90f63 100644 --- a/pyext/Makefile.am +++ b/pyext/Makefile.am @@ -9,6 +9,6 @@ _swsscommon_la_LDFLAGS = -module _swsscommon_la_LIBADD = ../common/libswsscommon.la -lpython$(PYTHON_VERSION) swsscommon_wrap.cpp: $(SWIG_SOURCES) - $(SWIG) -c++ -python -I../common -o $@ $< + $(SWIG) -Wall -c++ -python -I../common -o $@ $< CLEANFILES = swsscommon_wrap.cpp diff --git a/pyext/swsscommon.i b/pyext/swsscommon.i index de104d536..094a7ed6a 100644 --- a/pyext/swsscommon.i +++ b/pyext/swsscommon.i @@ -42,8 +42,8 @@ $result = PyList_New(1); PyList_SetItem($result, 0, temp); } - temp = SWIG_NewPointerObj(*$1, SWIGTYPE_p_swss__Selectable, SWIG_POINTER_OWN); - PyList_Append($result, temp); + temp = SWIG_NewPointerObj(*$1, SWIGTYPE_p_swss__Selectable, 0); + SWIG_Python_AppendOutput($result, temp); } %include "schema.h" %include "dbconnector.h" diff --git a/tests/test_redis_ut.py b/tests/test_redis_ut.py index ed8741325..81f6fe899 100644 --- a/tests/test_redis_ut.py +++ b/tests/test_redis_ut.py @@ -1,4 +1,6 @@ import time +from threading import Thread +from pympler.tracker import SummaryTracker from swsscommon import swsscommon def test_ProducerTable(): @@ -87,3 +89,36 @@ def test_DBConnectorRedisClientName(): db.setClientName(client_name) time.sleep(1) assert db.getClientName() == client_name + + +def test_SelectMemoryLeak(): + N = 50000 + def table_set(t, state): + fvs = swsscommon.FieldValuePairs([("status", state)]) + t.set("123", fvs) + + def generator_SelectMemoryLeak(): + app_db = swsscommon.DBConnector("APPL_DB", 0, True) + t = swsscommon.Table(app_db, "TABLE") + for i in xrange(N/2): + table_set(t, "up") + table_set(t, "down") + + tracker = SummaryTracker() + appl_db = swsscommon.DBConnector("APPL_DB", 0, True) + sel = swsscommon.Select() + sst = swsscommon.SubscriberStateTable(appl_db, "TABLE") + sel.addSelectable(sst) + thr = Thread(target=generator_SelectMemoryLeak) + thr.daemon = True + thr.start() + time.sleep(5) + for _ in xrange(N): + state, c = sel.select(1000) + diff = tracker.diff() + cases = [] + for name, count, _ in diff: + if count >= N: + cases.append("%s - %d objects for %d repeats" % (name, count, N)) + thr.join() + assert not cases