Commits

Raymond Hettinger  committed 812027f

Fix-up error-exits on struct_unpack().

  • Participants
  • Parent commits 4c7ebc3
  • Branches 2.5

Comments (0)

Files changed (1)

File Modules/_struct.c

 {
 	char *start;
 	int len;
-	PyObject * args;
+	PyObject *args=NULL, *result;
 	PyStructObject *soself = (PyStructObject *)self;
 	assert(PyStruct_Check(self));
 	assert(soself->s_codes != NULL);
-	if (inputstr != NULL && PyString_Check(inputstr) &&
+	if (inputstr == NULL)
+		goto fail;
+	if (PyString_Check(inputstr) &&
 		PyString_GET_SIZE(inputstr) == soself->s_size) {
 			return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
 	}
 	args = PyTuple_Pack(1, inputstr);
 	if (args == NULL)
 		return NULL;
-	if (!PyArg_ParseTuple(args, "s#:unpack", &start, &len)) {
-		Py_DECREF(args);
-		return NULL;
-	}
+	if (!PyArg_ParseTuple(args, "s#:unpack", &start, &len))
+		goto fail;
+	if (soself->s_size != len)
+		goto fail;
+	result = s_unpack_internal(soself, start);
 	Py_DECREF(args);
-	if (soself->s_size != len) {
-		PyErr_Format(StructError,
-			"unpack requires a string argument of length %zd",
-			soself->s_size);
-		return NULL;
-	}
-	return s_unpack_internal(soself, start);
+	return result;
+
+fail:
+	Py_XDECREF(args);
+	PyErr_Format(StructError,
+		"unpack requires a string argument of length %zd",
+		soself->s_size);
+	return NULL;
 }
 
 PyDoc_STRVAR(s_unpack_from__doc__,