diff options
author | Detlev Casanova <detlev.casanova@gmail.com> | 2010-07-15 12:09:26 +0200 |
---|---|---|
committer | Detlev Casanova <detlev.casanova@gmail.com> | 2010-07-15 12:09:26 +0200 |
commit | 01ff056a55b198b91ef327d7ca223bab9452034c (patch) | |
tree | 95d37232d7d2c543304bf10651d85d9e23ff83d7 /src/config.c | |
parent | fa75018c1432d0aaaf4674b502fe6cafdfd5156c (diff) | |
download | layman-01ff056a55b198b91ef327d7ca223bab9452034c.tar.gz layman-01ff056a55b198b91ef327d7ca223bab9452034c.tar.bz2 layman-01ff056a55b198b91ef327d7ca223bab9452034c.zip |
Get to work with the changes in layman.
Fix most of the memory leaks
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c index 624f1ab..47d4437 100644 --- a/src/config.c +++ b/src/config.c @@ -57,16 +57,44 @@ const char* bareConfigGetDefaultValue(BareConfig* cfg, const char* opt) return NULL; if (PyDict_Contains(obj, PyBytes_FromString(opt))) - return PyBytes_AsString(PyDict_GetItem(obj, PyBytes_FromString(opt))); + { + PyObject *pyopt = PyBytes_FromString(opt); + char *tmp = PyBytes_AsString(PyDict_GetItem(obj, pyopt)); + Py_DECREF(pyopt); + + char *ret = malloc(sizeof(char) * strlen(tmp)); + strcpy(ret, tmp); + Py_DECREF(obj); + + return ret; + } else return ""; } +const char* bareConfigGetOptionValue(BareConfig* cfg, const char* opt) +{ + PyObject *obj = PyObject_CallMethod(cfg->object, "get_option", "(z)", opt); + char *tmp = PyBytes_AsString(obj); + char *ret = malloc(sizeof(char) * (strlen(tmp) + 1)); + + strcpy(ret, tmp); + + Py_DECREF(obj); + + return ret; +} + int bareConfigSetOptionValue(BareConfig* cfg, const char* opt, const char* val) { PyObject *obj = PyObject_CallMethod(cfg->object, "set_option", "(zz)", opt, val); + int ret; if (obj) - return 1; + ret = 1; else - return 0; + ret = 0; + + Py_DECREF(obj); + + return ret; } |