Clean up some memory leaks

This commit is contained in:
whydoubt 2004-12-01 06:34:27 +00:00
parent 8362e4dc87
commit fd550a5f52
4 changed files with 28 additions and 15 deletions

View File

@ -1,3 +1,8 @@
Wed Dec 1 00:33:38 CST 2004 Jeff Smith <whydoubt@yahoo.com>
* src/libmdb/table.c:
* src/libmdb/iconv.c:
* src/util/mdb-sql.c: Clean up some memory leaks
Sat Nov 27 12:16:08 CST 2004 Jeff Smith <whydoubt@yahoo.com>
* src/odbc/odbc.c: Update ascii2unicode conversion calls

View File

@ -28,26 +28,26 @@ mdb_unicode2ascii(MdbHandle *mdb, unsigned char *buf, int offset, unsigned int l
{
unsigned int i, ret;
int len_in, len_out;
char *in_ptr, *out_ptr;
unsigned char *in_ptr, *out_ptr;
in_ptr = &buf[offset];
out_ptr = dest;
len_in = len;
len_out = dest_sz;
if (buf[offset]==0xff && buf[offset+1]==0xfe) {
if (in_ptr[0]==0xff && in_ptr[1]==0xfe) {
len_in -= 2;
in_ptr = &buf[offset+2];
ret = iconv(mdb->iconv_compress, &in_ptr, &len_in, &out_ptr, &len_out);
in_ptr += 2;
ret = iconv(mdb->iconv_compress, (char **)&in_ptr, &len_in, (char **)&out_ptr, &len_out);
dest[dest_sz - len_out]='\0';
return dest_sz - len_out;
//strncpy(dest, &buf[offset+2], len-2);
//strncpy(dest, in_ptr+2, len-2);
//dest[len-2]='\0';
} else {
#ifdef HAVE_ICONV
if (mdb->iconv_in) {
//printf("1 len_in %d len_out %d\n",len_in, len_out);
ret = iconv(mdb->iconv_in, &in_ptr, &len_in, &out_ptr, &len_out);
ret = iconv(mdb->iconv_in, (char **)&in_ptr, &len_in, (char **)&out_ptr, &len_out);
//printf("2 len_in %d len_out %d\n",len_in, len_out);
dest[dest_sz - len_out]='\0';
//printf("dest %s\n",dest);
@ -57,7 +57,7 @@ mdb_unicode2ascii(MdbHandle *mdb, unsigned char *buf, int offset, unsigned int l
/* convert unicode to ascii, rather sloppily */
for (i=0;i<len;i+=2)
dest[i/2] = buf[offset + i];
dest[i/2] = in_ptr[i];
dest[len/2]='\0';
}
return len;
@ -89,13 +89,13 @@ mdb_ascii2unicode(MdbHandle *mdb, unsigned char *buf, int offset, unsigned int l
#endif
if (IS_JET3(mdb)) {
strncpy(dest, &buf[offset], len);
strncpy(dest, in_ptr, len);
dest[len]='\0';
return strlen(dest);
}
while (i<strlen(&buf[offset]) && (i*2+2)<len) {
dest[i*2] = buf[offset+i];
while (i<strlen(in_ptr) && (i*2+2)<len) {
dest[i*2] = in_ptr[i];
dest[i*2+1] = 0;
i++;
}
@ -120,13 +120,15 @@ void mdb_iconv_init(MdbHandle *mdb)
/* XXX - need to determine character set from file */
mdb->iconv_out = iconv_open("ISO8859-1", iconv_code);
mdb->iconv_in = iconv_open(iconv_code, "ISO8859-1");
mdb->iconv_compress = (iconv_t)-1;
}
#endif
}
void mdb_iconv_close(MdbHandle *mdb)
{
#ifdef HAVE_ICONV
if (mdb->iconv_out != -1) iconv_close(mdb->iconv_out);
if (mdb->iconv_in != -1) iconv_close(mdb->iconv_in);
if (mdb->iconv_out != (iconv_t)-1) iconv_close(mdb->iconv_out);
if (mdb->iconv_in != (iconv_t)-1) iconv_close(mdb->iconv_in);
if (mdb->iconv_compress != (iconv_t)-1) iconv_close(mdb->iconv_compress);
#endif
}

View File

@ -58,9 +58,12 @@ void mdb_free_tabledef(MdbTableDef *table)
if (!table) return;
if (table->is_temp_table) {
unsigned int i;
/* Temp table pages are being stored in memory */
for (i=0; i<table->temp_table_pages->len; i++)
g_free(g_ptr_array_index(table->temp_table_pages,i));
g_ptr_array_free(table->temp_table_pages, TRUE);
/* Temp tables use dummy entries */
g_free(table->entry);
}
mdb_free_columns(table->columns);
mdb_free_indices(table->indices);

View File

@ -42,6 +42,7 @@ char *cmdline = NULL;
extern void add_history ();
extern int write_history ();
extern int read_history ();
extern void clear_history ();
# endif
#endif /* HAVE_READLINE_HISTORY */
@ -353,9 +354,9 @@ dump_results_pp(MdbSQL *sql)
int
main(int argc, char **argv)
{
char *s;
char *s = NULL;
char prompt[20];
int line;
int line = 0;
char *mybuf;
unsigned int bufsz;
MdbSQL *sql;
@ -419,10 +420,11 @@ char *delimiter = NULL;
bufsz = 4096;
mybuf = (char *) g_malloc(bufsz);
mybuf[0]='\0';
line = 0;
while (1) {
line ++;
if (s) free(s);
if (in) {
s=malloc(256);
if ((!s) || (!fgets(s, 256, in))) {
@ -482,6 +484,7 @@ char *delimiter = NULL;
histpath = (char *) g_strconcat(home, "/", HISTFILE, NULL);
write_history(histpath);
g_free(histpath);
clear_history();
}
#endif