fixed a memory leak bug in the uci module
This commit is contained in:
parent
31edff2391
commit
b53fe11c04
@ -12,11 +12,11 @@ libawksys_la_SOURCES = sys.c
|
||||
libawksys_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libawksys_la_LIBADD = -lqseawk -lqsecmn
|
||||
|
||||
#if HAVE_LIBUCI
|
||||
if HAVE_LIBUCI
|
||||
|
||||
mod_LTLIBRARIES += libawkuci.la
|
||||
libawkuci_la_SOURCES = uci.c
|
||||
libawkuci_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libawkuci_la_LIBADD = -lqseawk -lqsecmn $(UCI_LIBS)
|
||||
|
||||
#endif
|
||||
endif
|
||||
|
@ -34,6 +34,7 @@ PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
@HAVE_LIBUCI_TRUE@am__append_1 = libawkuci.la
|
||||
subdir = mod/awk
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
@ -85,12 +86,14 @@ libawksys_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libawksys_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
am__DEPENDENCIES_1 =
|
||||
libawkuci_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libawkuci_la_OBJECTS = uci.lo
|
||||
@HAVE_LIBUCI_TRUE@libawkuci_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am__libawkuci_la_SOURCES_DIST = uci.c
|
||||
@HAVE_LIBUCI_TRUE@am_libawkuci_la_OBJECTS = uci.lo
|
||||
libawkuci_la_OBJECTS = $(am_libawkuci_la_OBJECTS)
|
||||
libawkuci_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libawkuci_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@HAVE_LIBUCI_TRUE@am_libawkuci_la_rpath = -rpath $(moddir)
|
||||
DEFAULT_INCLUDES =
|
||||
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
@ -105,7 +108,8 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libawksys_la_SOURCES) $(libawkuci_la_SOURCES)
|
||||
DIST_SOURCES = $(libawksys_la_SOURCES) $(libawkuci_la_SOURCES)
|
||||
DIST_SOURCES = $(libawksys_la_SOURCES) \
|
||||
$(am__libawkuci_la_SOURCES_DIST)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
@ -287,15 +291,13 @@ AM_CPPFLAGS = \
|
||||
-I$(includedir)
|
||||
|
||||
moddir = $(libdir)/qse
|
||||
|
||||
#if HAVE_LIBUCI
|
||||
mod_LTLIBRARIES = libawksys.la libawkuci.la
|
||||
mod_LTLIBRARIES = libawksys.la $(am__append_1)
|
||||
libawksys_la_SOURCES = sys.c
|
||||
libawksys_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libawksys_la_LIBADD = -lqseawk -lqsecmn
|
||||
libawkuci_la_SOURCES = uci.c
|
||||
libawkuci_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libawkuci_la_LIBADD = -lqseawk -lqsecmn $(UCI_LIBS)
|
||||
@HAVE_LIBUCI_TRUE@libawkuci_la_SOURCES = uci.c
|
||||
@HAVE_LIBUCI_TRUE@libawkuci_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
@HAVE_LIBUCI_TRUE@libawkuci_la_LIBADD = -lqseawk -lqsecmn $(UCI_LIBS)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
@ -364,7 +366,7 @@ clean-modLTLIBRARIES:
|
||||
libawksys.la: $(libawksys_la_OBJECTS) $(libawksys_la_DEPENDENCIES) $(EXTRA_libawksys_la_DEPENDENCIES)
|
||||
$(libawksys_la_LINK) -rpath $(moddir) $(libawksys_la_OBJECTS) $(libawksys_la_LIBADD) $(LIBS)
|
||||
libawkuci.la: $(libawkuci_la_OBJECTS) $(libawkuci_la_DEPENDENCIES) $(EXTRA_libawkuci_la_DEPENDENCIES)
|
||||
$(libawkuci_la_LINK) -rpath $(moddir) $(libawkuci_la_OBJECTS) $(libawkuci_la_LIBADD) $(LIBS)
|
||||
$(libawkuci_la_LINK) $(am_libawkuci_la_rpath) $(libawkuci_la_OBJECTS) $(libawkuci_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
@ -609,8 +611,6 @@ uninstall-am: uninstall-modLTLIBRARIES
|
||||
uninstall-am uninstall-modLTLIBRARIES
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
@ -6,26 +6,7 @@
|
||||
#if defined(HAVE_UCI_H)
|
||||
# include <uci.h>
|
||||
#else
|
||||
/*# error this module needs uci.h*/
|
||||
|
||||
#include <stdlib.h>
|
||||
struct uci_context
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
struct uci_context* uci_alloc_context(void)
|
||||
{
|
||||
qse_printf (QSE_T("uci_alloc_context....\n"));
|
||||
return malloc (sizeof(struct uci_context));
|
||||
}
|
||||
|
||||
void uci_free_context (struct uci_context* c)
|
||||
{
|
||||
qse_printf (QSE_T("uci_free_context....\n"));
|
||||
free (c);
|
||||
}
|
||||
# error this module needs uci.h
|
||||
#endif
|
||||
|
||||
typedef struct uctx_list_t uctx_list_t;
|
||||
@ -45,6 +26,7 @@ struct uctx_list_t
|
||||
uctx_node_t* tail;
|
||||
uctx_node_t* free;
|
||||
|
||||
/* mapping table to map 'id' to 'node' */
|
||||
struct
|
||||
{
|
||||
uctx_node_t** tab;
|
||||
@ -124,17 +106,18 @@ static void free_uctx_node (qse_awk_rtx_t* rtx, uctx_list_t* list, uctx_node_t*
|
||||
|
||||
list->map.tab[node->id] = QSE_NULL;
|
||||
|
||||
uci_free_context (node->ctx);
|
||||
|
||||
if (list->map.high == node->id + 1)
|
||||
{
|
||||
/* destroy the actual node if the node to be freed has the
|
||||
* highest id */
|
||||
uci_free_context (node->ctx);
|
||||
QSE_MMGR_FREE (qse_awk_rtx_getmmgr(rtx), node);
|
||||
list->map.high--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* otherwise, chain it to the free list */
|
||||
/* otherwise, chain the node to the free list */
|
||||
node->next = list->free;
|
||||
list->free = node;
|
||||
}
|
||||
@ -156,6 +139,7 @@ static void free_uctx_node (qse_awk_rtx_t* rtx, uctx_list_t* list, uctx_node_t*
|
||||
QSE_MMGR_FREE (mmgr, curnode);
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("freeing map...\n"));
|
||||
QSE_MMGR_FREE (mmgr, list->map.tab);
|
||||
list->map.high = 0;
|
||||
list->map.capa = 0;
|
||||
@ -211,7 +195,7 @@ static int fnc_uci_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
list = rtx_to_list (rtx, fi);
|
||||
|
||||
n = qse_awk_rtx_valtolong (
|
||||
rtx, qse_awk_rtx_getarg(rtx, 0), &id);
|
||||
rtx, qse_awk_rtx_getarg (rtx, 0), &id);
|
||||
if (n <= -1) return -1;
|
||||
|
||||
retv = qse_awk_rtx_makeintval (
|
||||
|
Loading…
x
Reference in New Issue
Block a user