comparison Python/codecs.c @ 12048:f87b56eebacc legacy-trunk

Marc-Andre Lemburg: Andy Robinson noted a core dump in the codecs.c file. This was introduced by my latest patch which fixed a memory leak in codecs.c. The bug causes all successful codec lookups to fail.
author Guido van Rossum <guido@python.org>
date Fri, 24 Mar 2000 20:52:23 +0000
parents 7994d9db7f4d
children bc861add5d71
comparison
equal deleted inserted replaced
12047:fa12a563368d 12048:f87b56eebacc
91 91
92 If no codec is found, a KeyError is set and NULL returned. */ 92 If no codec is found, a KeyError is set and NULL returned. */
93 93
94 PyObject *_PyCodec_Lookup(const char *encoding) 94 PyObject *_PyCodec_Lookup(const char *encoding)
95 { 95 {
96 PyObject *result, *args = NULL, *v = NULL; 96 PyObject *result, *args = NULL, *v;
97 int i, len; 97 int i, len;
98 98
99 if (_PyCodec_SearchCache == NULL || _PyCodec_SearchPath == NULL) { 99 if (_PyCodec_SearchCache == NULL || _PyCodec_SearchPath == NULL) {
100 PyErr_SetString(PyExc_SystemError, 100 PyErr_SetString(PyExc_SystemError,
101 "codec module not properly initialized"); 101 "codec module not properly initialized");
117 Py_DECREF(v); 117 Py_DECREF(v);
118 return result; 118 return result;
119 } 119 }
120 120
121 /* Next, scan the search functions in order of registration */ 121 /* Next, scan the search functions in order of registration */
122 args = PyTuple_New(1);
123 if (args == NULL)
124 goto onError;
125 PyTuple_SET_ITEM(args,0,v);
126
122 len = PyList_Size(_PyCodec_SearchPath); 127 len = PyList_Size(_PyCodec_SearchPath);
123 if (len < 0) 128 if (len < 0)
124 goto onError; 129 goto onError;
125
126 args = PyTuple_New(1);
127 if (args == NULL)
128 goto onError;
129 PyTuple_SET_ITEM(args,0,v);
130 v = NULL;
131 130
132 for (i = 0; i < len; i++) { 131 for (i = 0; i < len; i++) {
133 PyObject *func; 132 PyObject *func;
134 133
135 func = PyList_GetItem(_PyCodec_SearchPath, i); 134 func = PyList_GetItem(_PyCodec_SearchPath, i);
136 if (func == NULL) 135 if (func == NULL)
137 goto onError; 136 goto onError;
138 result = PyEval_CallObject(func,args); 137 result = PyEval_CallObject(func, args);
139 if (result == NULL) 138 if (result == NULL)
140 goto onError; 139 goto onError;
141 if (result == Py_None) { 140 if (result == Py_None) {
142 Py_DECREF(result); 141 Py_DECREF(result);
143 continue; 142 continue;
161 PyDict_SetItem(_PyCodec_SearchCache, v, result); 160 PyDict_SetItem(_PyCodec_SearchCache, v, result);
162 Py_DECREF(args); 161 Py_DECREF(args);
163 return result; 162 return result;
164 163
165 onError: 164 onError:
166 Py_XDECREF(v);
167 Py_XDECREF(args); 165 Py_XDECREF(args);
168 return NULL; 166 return NULL;
169 } 167 }
170 168
171 static 169 static