@@ -1243,8 +1243,13 @@ int yara_callback(
12431243 continue ;
12441244
12451245 string_instance_list = PyList_New (0 );
1246+
12461247 if (string_instance_list == NULL )
1247- return PyErr_Format (PyExc_TypeError , "Out of memory" );
1248+ {
1249+ PyErr_Format (PyExc_TypeError , "out of memory" );
1250+ return CALLBACK_ERROR ;
1251+ }
1252+
12481253
12491254 yr_string_matches_foreach (context , string , m )
12501255 {
@@ -1255,8 +1260,13 @@ int yara_callback(
12551260 object ,
12561261 m -> match_length ,
12571262 m -> xor_key );
1263+
12581264 if (string_match_instance == NULL )
1259- return PyErr_Format (PyExc_TypeError , "Out of memory" );
1265+ {
1266+ Py_DECREF (object );
1267+ PyErr_Format (PyExc_TypeError , "out of memory" );
1268+ return CALLBACK_ERROR ;
1269+ }
12601270
12611271 PyList_Append (string_instance_list , string_match_instance );
12621272
@@ -1268,8 +1278,14 @@ int yara_callback(
12681278 string -> identifier ,
12691279 string -> flags ,
12701280 string_instance_list );
1281+
12711282 if (object == NULL )
1272- return PyErr_Format (PyExc_TypeError , "Out of memory" );
1283+ {
1284+ PyErr_Format (PyExc_TypeError , "out of memory" );
1285+ return CALLBACK_ERROR ;
1286+ }
1287+
1288+
12731289 Py_DECREF (string_instance_list );
12741290
12751291 PyList_Append (string_list , object );
@@ -3096,13 +3112,15 @@ static PyMethodDef yara_methods[] = {
30963112static PyObject * YaraWarningError_getwarnings (PyObject * self , void * closure )
30973113{
30983114 PyObject * args = PyObject_GetAttrString (self , "args" );
3115+
30993116 if (!args ) {
31003117 return NULL ;
31013118 }
31023119
31033120 PyObject * ret = PyTuple_GetItem (args , 0 );
31043121 Py_XINCREF (ret );
31053122 Py_XDECREF (args );
3123+
31063124 return ret ;
31073125}
31083126
@@ -3191,6 +3209,7 @@ MOD_INIT(yara)
31913209 }
31923210
31933211 PyObject * module_names_list = PyList_New (0 );
3212+
31943213 if (module_names_list == NULL )
31953214 {
31963215 PyErr_SetString (YaraError , "module list error" );
0 commit comments