Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:29:13+00:00 2026-06-16T20:29:13+00:00

OK, I’m getting a strange error after using Cython’s C++ support as I think

  • 0

OK, I’m getting a strange error after using Cython’s C++ support as I think the manual advises (to use __cinit__ to allocate heap RAM and __dealloc__ to free it again.

I have a C++ class which calloc and mallocs some RAM in its constructor and frees it in the destructor. I will post this if necessary, but the error isn’t coming from C++ land, and the new and delete calls work fine, so I’ll just give you the cython for now:

cdef extern from "../clibs/adjacency.hpp":

  cdef cppclass Adjacency:
    int* _bv
    void** _meta
    unsigned int length
    Adjacency(int graph_order, int meta_on)
    int get(int i, int j)
    void set(int i, int j, int on, void* meta)
    void reset_to_zero()
    void edges_iter(void* global_meta, void (*callback)(void*, int, int, void*))

cdef class Graph:
  cdef Adjacency* adj

  def __init__(self, graph_order):
    print "__init__"

  def __cinit__(self, graph_order, *args, **kwargs):
    print "__cinit__"
    print "allocating, no meta."
    self.adj = new Adjacency(<int>graph_order, 0)

  def __dealloc__(self):
    print "__dealloc__"
    del self.adj

When I test this, I get the following:

In [1]: import graph

In [2]: g = graph.Graph(302)
__cinit__
allocating, no meta.
__init__

In [3]: ^D
Do you really want to exit ([y]/n)? 
__dealloc__
Python(7389,0x7fff70f9acc0) malloc: *** error for object 0x100defa08: incorrect
checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap

I also sometimes get a segfault instead of an incorrect checksum.

I cracked open the C++ file that cython generated and added the following around the delete call:

/* "graph.pyx":75
 *   def __dealloc__(self):
 *     print "__dealloc__"
 *     del self.adj             # <<<<<<<<<<<<<<
 * 
 *   def __init__(self, graph_order):
 */
printf("about to delete adj:\n");
delete __pyx_v_self->adj;
printf("just deleted adj!\n");

and we can clearly see that the call I made to delete runs fine:

In [1]: import graph

In [2]: g = graph.Graph(302)
__cinit__
allocating, no meta.
__init__

In [3]: ^D
Do you really want to exit ([y]/n)? 
__dealloc__
about to delete adj:
just deleted adj!
Python(7389,0x7fff70f9acc0) malloc: *** error for object 0x100defa08: incorrect
checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap

And that Python throws a tantrum after I’m done tidying up as I was told to in the Cython manual.

I also just tried setting self.adj = NULL in __dealloc__, in case Python was trying to see inside my object, but that didn’t help.

Any ideas what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:29:15+00:00Added an answer on June 16, 2026 at 8:29 pm

    I had made a mistake in my C++ code (which I didn’t show).

    I had a bunch of functions like this:

    if (_meta != NULL) {
      // do stuff with _meta, like loop over the void*s
    }
    

    But in the constructor, I was calling one of these before setting _meta = NULL; …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.