Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualrip-off

Posted 23 June 2013 - 05:24 AM

Hi everyone,
 
my question is a c++ based topic, but I'm using Cocoa and Xcode.
 
I'm allocating sone buffers to send files over the network.
When i read the network-input into the buffer i process it in another object called Controller.
after that i want to release(free) the buffer in order not to get any memory leaks.
But here's my problem the program crashes and says:
 

Game(3984,0x103481000) malloc: *** error for object 0x102009600: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
but why? Here's the code:
 
So this is the code of my Network-Controller which gets the input as follows:
int n = 0;
    char *buffer = malloc(2049*sizeof(char));
    while ( (n = (int)read( sockfd, buffer, 2048)) ) {
        buffer[n] = '0';
        [cont networkinput:buffer length:n];
        free(buffer); Error!!!
    }
    connected = NO;
[cont networkinput:buffer length:n];
sends the buffer to the Controller and the class processes it.
 
 
but why not allocated? I used malloc.
 
Can anyone help me? If I take out the freeing my memory must be increased to 1000GB 
 
Thanks a lot

: Mod edit, restoring redacted post


#3Astado89

Posted 22 June 2013 - 01:08 PM

problem solved!!

 

Sorry!!!


#2Astado89

Posted 22 June 2013 - 01:08 PM

problem solved!!


#1Astado89

Posted 22 June 2013 - 12:58 PM

Hi everyone,

 

my question is a c++ based topic, but I'm using Cocoa and Xcode.

 

I'm allocating sone buffers to send files over the network.

When i read the network-input into the buffer i process it in another object called Controller.

after that i want to release(free) the buffer in order not to get any memory leaks.

But here's my problem the program crashes and says:

 

 

Game(3984,0x103481000) malloc: *** error for object 0x102009600: pointer being freed was not allocated

*** set a breakpoint in malloc_error_break to debug

 

but why? Here's the code:

 

So this is the code of my Network-Controller which gets the input as follows:

int n = 0;
    char *buffer = malloc(2049*sizeof(char));
    while ( (n = (int)read( sockfd, buffer, 2048)) ) {
        buffer[n] = '0';
        [cont networkinput:buffer length:n];
        free(buffer); Error!!!
    }
    connected = NO;

[cont networkinput:buffer length:n]; sends the buffer to the Controller and the class processes it.

 


but why not allocated? I used malloc.
 
Can anyone help me? If I take out the freeing my memory must be increased to 1000GB :)
 
Thanks a lot

PARTNERS