Show More
@@ -62,11 +62,11 b' static PyObject *bdiff(PyObject *self, P' | |||||
62 | { |
|
62 | { | |
63 | char *sa, *sb, *rb, *ia, *ib; |
|
63 | char *sa, *sb, *rb, *ia, *ib; | |
64 | PyObject *result = NULL; |
|
64 | PyObject *result = NULL; | |
65 | struct bdiff_line *al, *bl; |
|
65 | struct bdiff_line *al = NULL, *bl = NULL; | |
66 | struct bdiff_hunk l, *h; |
|
66 | struct bdiff_hunk l, *h; | |
67 | int an, bn, count; |
|
67 | int an, bn, count; | |
68 | Py_ssize_t len = 0, la, lb, li = 0, lcommon = 0, lmax; |
|
68 | Py_ssize_t len = 0, la, lb, li = 0, lcommon = 0, lmax; | |
69 | PyThreadState *_save; |
|
69 | PyThreadState *_save = NULL; | |
70 |
|
70 | |||
71 | l.next = NULL; |
|
71 | l.next = NULL; | |
72 |
|
72 | |||
@@ -89,12 +89,16 b' static PyObject *bdiff(PyObject *self, P' | |||||
89 |
|
89 | |||
90 | an = bdiff_splitlines(sa + lcommon, la - lcommon, &al); |
|
90 | an = bdiff_splitlines(sa + lcommon, la - lcommon, &al); | |
91 | bn = bdiff_splitlines(sb + lcommon, lb - lcommon, &bl); |
|
91 | bn = bdiff_splitlines(sb + lcommon, lb - lcommon, &bl); | |
92 | if (!al || !bl) |
|
92 | if (!al || !bl) { | |
93 | goto nomem; |
|
93 | PyErr_NoMemory(); | |
|
94 | goto cleanup; | |||
|
95 | } | |||
94 |
|
96 | |||
95 | count = bdiff_diff(al, an, bl, bn, &l); |
|
97 | count = bdiff_diff(al, an, bl, bn, &l); | |
96 | if (count < 0) |
|
98 | if (count < 0) { | |
97 | goto nomem; |
|
99 | PyErr_NoMemory(); | |
|
100 | goto cleanup; | |||
|
101 | } | |||
98 |
|
102 | |||
99 | /* calculate length of output */ |
|
103 | /* calculate length of output */ | |
100 | la = lb = 0; |
|
104 | la = lb = 0; | |
@@ -110,7 +114,7 b' static PyObject *bdiff(PyObject *self, P' | |||||
110 | result = PyBytes_FromStringAndSize(NULL, len); |
|
114 | result = PyBytes_FromStringAndSize(NULL, len); | |
111 |
|
115 | |||
112 | if (!result) |
|
116 | if (!result) | |
113 |
goto |
|
117 | goto cleanup; | |
114 |
|
118 | |||
115 | /* build binary patch */ |
|
119 | /* build binary patch */ | |
116 | rb = PyBytes_AsString(result); |
|
120 | rb = PyBytes_AsString(result); | |
@@ -130,13 +134,19 b' static PyObject *bdiff(PyObject *self, P' | |||||
130 | lb = h->b2; |
|
134 | lb = h->b2; | |
131 | } |
|
135 | } | |
132 |
|
136 | |||
133 | nomem: |
|
137 | cleanup: | |
134 | if (_save) |
|
138 | if (_save) | |
135 | PyEval_RestoreThread(_save); |
|
139 | PyEval_RestoreThread(_save); | |
136 |
|
|
140 | if (al) { | |
137 |
free( |
|
141 | free(al); | |
138 | bdiff_freehunks(l.next); |
|
142 | } | |
139 | return result ? result : PyErr_NoMemory(); |
|
143 | if (bl) { | |
|
144 | free(bl); | |||
|
145 | } | |||
|
146 | if (l.next) { | |||
|
147 | bdiff_freehunks(l.next); | |||
|
148 | } | |||
|
149 | return result; | |||
140 | } |
|
150 | } | |
141 |
|
151 | |||
142 | /* |
|
152 | /* |
General Comments 0
You need to be logged in to leave comments.
Login now