diff options
author | Guido van Rossum <guido@python.org> | 1993-11-05 10:14:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-11-05 10:14:49 (GMT) |
commit | 572d2d994df1b865296a1f09bdfeaccf4f51bbd9 (patch) | |
tree | 1785fafcd006428fcccfc6d267e26d1ccfc3df60 /Modules/stropmodule.c | |
parent | e77a757094f68351f336044654cd91575c677896 (diff) | |
download | cpython-572d2d994df1b865296a1f09bdfeaccf4f51bbd9.zip cpython-572d2d994df1b865296a1f09bdfeaccf4f51bbd9.tar.gz cpython-572d2d994df1b865296a1f09bdfeaccf4f51bbd9.tar.bz2 |
Fix memory leaks in join & joinfields
Diffstat (limited to 'Modules/stropmodule.c')
-rw-r--r-- | Modules/stropmodule.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index 477d14d..fe67ca0 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -37,7 +37,7 @@ strop_split(self, args) object *self; /* Not used */ object *args; { - int len, i, j; + int len, i, j, err; char *s; char c; object *list, *item; @@ -61,7 +61,13 @@ strop_split(self, args) } if (j < i) { item = newsizedstringobject(s+j, (int)(i-j)); - if (item == NULL || addlistitem(list, item) < 0) { + if (item == NULL) { + DECREF(list); + return NULL; + } + err = addlistitem(list, item); + DECREF(item); + if (err < 0) { DECREF(list); return NULL; } @@ -77,7 +83,7 @@ strop_splitfields(self, args) object *self; /* Not used */ object *args; { - int len, n, i, j; + int len, n, i, j, err; char *s, *sub; object *list, *item; @@ -96,22 +102,30 @@ strop_splitfields(self, args) while (i+n <= len) { if (s[i] == sub[0] && (n == 1 || strncmp(s+i, sub, n) == 0)) { item = newsizedstringobject(s+j, (int)(i-j)); - if (item == NULL || addlistitem(list, item) < 0) { - DECREF(list); - return NULL; - } + if (item == NULL) + goto fail; + err = addlistitem(list, item); + DECREF(item); + if (err < 0) + goto fail; i = j = i + n; } else i++; } item = newsizedstringobject(s+j, (int)(len-j)); - if (item == NULL || addlistitem(list, item) < 0) { - DECREF(list); - return NULL; - } + if (item == NULL) + goto fail; + err = addlistitem(list, item); + DECREF(item); + if (err < 0) + goto fail; return list; + + fail: + DECREF(list); + return NULL; } |