[GRASS-SVN] r50370 - grass/trunk/lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jan 21 16:05:55 EST 2012
Author: mmetz
Date: 2012-01-21 13:05:54 -0800 (Sat, 21 Jan 2012)
New Revision: 50370
Modified:
grass/trunk/lib/db/dbmi_base/string.c
Log:
db lib: attempt to fix some more memory leaks
Modified: grass/trunk/lib/db/dbmi_base/string.c
===================================================================
--- grass/trunk/lib/db/dbmi_base/string.c 2012-01-21 20:53:13 UTC (rev 50369)
+++ grass/trunk/lib/db/dbmi_base/string.c 2012-01-21 21:05:54 UTC (rev 50370)
@@ -24,7 +24,7 @@
*/
void db_init_string(dbString * x)
{
- x->string = "";
+ x->string = NULL;
x->nalloc = 0;
}
@@ -79,7 +79,8 @@
*/
void db_zero_string(dbString * x)
{
- db_zero((void *)db_get_string(x), db_sizeof_string(x));
+ if (db_get_string(x) && x->nalloc > 0)
+ db_zero((void *)db_get_string(x), x->nalloc);
}
static int set_string(dbString * x, char *s, int copy)
@@ -103,7 +104,7 @@
else {
db_free_string(x);
x->string = s;
- x->nalloc = -1;
+ x->nalloc = -1; /* fixme */
}
return DB_OK;
}
@@ -119,9 +120,14 @@
*/
int db_enlarge_string(dbString * x, int len)
{
- if (x->nalloc < len) {
- if (x->nalloc <= 0)
- x->string = db_store("");
+ if (x->nalloc <= 0) {
+ x->string = db_malloc(len * sizeof(char));
+ if (x->string == NULL)
+ return DB_MEMORY_ERR;
+ x->nalloc = len;
+ strcpy(x->string, "");
+ }
+ else if (x->nalloc < len) {
x->string = db_realloc((void *)x->string, len);
if (x->string == NULL)
return DB_MEMORY_ERR;
@@ -149,7 +155,7 @@
*/
void db_free_string(dbString * x)
{
- if (x->nalloc > 0)
+ if (x->nalloc != 0)
db_free(x->string);
db_init_string(x);
}
@@ -207,7 +213,10 @@
int len;
int stat;
- len = strlen(db_get_string(x)) + strlen(s) + 1;
+ if (db_get_string(x))
+ len = strlen(db_get_string(x)) + strlen(s) + 1;
+ else
+ len = strlen(s) + 1;
stat = db_enlarge_string(x, len);
if (stat != DB_OK)
return stat;
More information about the grass-commit
mailing list