Skip to content

Commit

Permalink
Improved method of freeing memory used by the fetchone call. Now we j…
Browse files Browse the repository at this point in the history
…ust call the C function free() directly, rather than relying on a custom wrapper.
  • Loading branch information
Israel Brewster committed Dec 23, 2014
1 parent 4512ff7 commit 706feaa
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
p4d is a Python Database API 2.0 compliant driver for the 4D (4th Dimension) database server. As such, usage should be familiar to anyone who has used any python database modules before. This module is based off of a C library provided by 4D, and integrated with Python using CFFI. As such, installation of this module does require CFFI.

v0.5.1 2014-12-23:
- Imporoved method of freeing memory used by the fetchone call

v0.5 2014-12-22:
- Fix remaining memory leak with execute many call. Turns out there were leaks both in the C library as well as in how I was calling the library. Testing now shows memory usage stable at 11MB when processing a 1,000,000 record result set.

Expand Down
6 changes: 0 additions & 6 deletions lib4d_sql/fourd.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ void * fourd_field(FOURD_RESULT *res,unsigned int numCol)
return elmt->pValue;
}

//This function is for use by the python 4d driver, as it appears to be the only
//way to get this block of memory freed. Hopefully that will change.
void _free_field_string(char **value){
free(*value);
}

int fourd_field_to_string(FOURD_RESULT *res,unsigned int numCol,char **value,size_t *len)
{
unsigned int nbCol=res->row_type.nbColumn;
Expand Down
3 changes: 0 additions & 3 deletions lib4d_sql/fourd.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,6 @@ const char * fourd_sqlstate(FOURD *cnx);
void fourd_free(FOURD* cnx);
void fourd_free_statement(FOURD_STATEMENT *state);
void fourd_timeout(FOURD* cnx,int timeout);
//For use by external non-c code that can't access/clear this block of memory
//directly.
void _free_field_string(char **value);

/*function on FOURD_RESULT*/
FOURD_LONG8 fourd_num_rows(FOURD_RESULT *result);
Expand Down
2 changes: 1 addition & 1 deletion p4d/p4d.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def fetchone(self):
self.lib4d_sql.fourd_field_to_string(self.result, col, inbuff, strlen)
strdata = inbuff[0]
output = str(ffi.buffer(strdata, strlen[0])[:])
self.lib4d_sql._free_field_string(inbuff)
self.lib4d_sql.free(strdata) #must call free explicitly, otherwise we leak.

if fieldtype==self.lib4d_sql.VK_STRING or fieldtype==self.lib4d_sql.VK_TEXT:
row.append(output.decode('UTF-16LE'))
Expand Down
4 changes: 3 additions & 1 deletion p4d/py_fourd.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,7 @@ int fourd_field_to_string(FOURD_RESULT *res,unsigned int numCol,char **value,siz

int fourd_errno(FOURD *cnx);
const char * fourd_error(FOURD *cnx);
void _free_field_string(char **value);

/* Misc other C functions needed by the p4d driver */
void free(void *);

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def finalize_options(self):
setup(
zip_safe=False,
name="p4d",
version="0.5",
version="0.5.1",
install_requires=["cffi", ],
setup_requires=['cffi', ],
packages=find_packages(),
Expand Down

0 comments on commit 706feaa

Please sign in to comment.