summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2016-11-09 18:05:27 -0500
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2016-11-09 18:05:27 -0500
commit863bf62a86fe0436f4902a4dc877e46a3dfa4951 (patch)
treeace896486b30a30f14e3b03edd13e832103fabfa
parent919ab60abe326b7cb8d471403bcc0ed969c19d4a (diff)
downloadpyisda-863bf62a86fe0436f4902a4dc877e46a3dfa4951.tar.gz
fix memory leak
-rw-r--r--pyisda/flat_hazard.pyx18
1 files changed, 13 insertions, 5 deletions
diff --git a/pyisda/flat_hazard.pyx b/pyisda/flat_hazard.pyx
index 83a0d4a..7549a38 100644
--- a/pyisda/flat_hazard.pyx
+++ b/pyisda/flat_hazard.pyx
@@ -2,10 +2,14 @@ from date cimport dcc, TDate
cimport numpy as np
from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake,
- TContingentLeg, TFeeLeg, JpmcdsContingentLegPV, JpmcdsFeeLegPV)
-from curve cimport TCurve, YieldCurve, SpreadCurve, JpmcdsCleanSpreadCurve
-from date cimport pydate_to_TDate
+ TContingentLeg, TFeeLeg, JpmcdsContingentLegPV, JpmcdsFeeLegPV,
+ JpmcdsFeeLegFree)
+from curve cimport (TCurve, YieldCurve, SpreadCurve, JpmcdsCleanSpreadCurve,
+ JpmcdsFreeTCurve, JpmcdsMakeTCurve, CONTINUOUS)
+from date cimport pydate_to_TDate, ACT_360, ACT_365F
from cdsone cimport JpmcdsStringToStubMethod, TStubMethod
+from cpython.mem cimport PyMem_Malloc, PyMem_Free
+from libc.stdlib cimport free
cimport cython
import numpy as np
@@ -40,7 +44,7 @@ def strike_vec(double[:] spreads, YieldCurve yc, trade_date, value_date,
&stub_type,
1., # notional
1., # coupon_rate
- 3, # JPMCDS_ACT_360
+ ACT_360, # JPMCDS_ACT_360
<long>'M',
b'NONE',
1) # protect_start = True
@@ -58,7 +62,7 @@ def strike_vec(double[:] spreads, YieldCurve yc, trade_date, value_date,
recovery_rate,
1, # pay_accrued_on_default True
NULL,
- 3, # JPMCDS_ACT_360
+ ACT_360, # JPMCDS_ACT_360
&stub_type,
<long>'M',
b'NONE')
@@ -69,4 +73,8 @@ def strike_vec(double[:] spreads, YieldCurve yc, trade_date, value_date,
if JpmcdsFeeLegPV(fee_leg, trade_date_c, step_in_date_c, value_date_c,
yc._thisptr, sc, True, &coupon_leg_pv[i]) != 0:
raise ValueError("Something went wrong")
+ JpmcdsFeeLegFree(fee_leg)
+ free(default_leg)
+ if sc is not NULL:
+ JpmcdsFreeTCurve(sc)
return default_leg_pv, coupon_leg_pv