release memory of returned values/pointers to CvMat
===

I have got a problem to release memory with OpenCV. 
How can I release memory of a returned pointer? 

Here is my code: 

This is the function where I a call the function thinning: 

 

    int preprocessing_and_classification() { 
    
    /// Section 2D - Perform morphological processing 
    
                CvMat* image1_edge_morpho = thinning(image1_edge); 
                            ....... 
                            ....... 
                            ........... 
                            
                            //////////////// release the memory /////////////// 
                cvReleaseImage(&img); 
                cvReleaseMat(&image1); 
                cvReleaseMat(&image1_edge); 
                cvReleaseMat(&image1_edge_morpho); 
                cvReleaseImage(&imgg); 
                cvReleaseImage(&imggT); 
                cvReleaseMemStorage(&g_storage); 
                cvReleaseMat(&features); 
                cvReleaseMat(&labels_obtained); 
                ///////////////////////////////////////////////////// 
    return num_bacilli; 
    
    } 
    

The function thinning which you can see below returns the Pointer Merode: 



    CvMat* thinning(CvMat* M){ 
    
    /* 
    Input parameters 
    CvMat* M = Pointer to the matrix on which morphological processing needs to be done. 
    
    Output parameters 
    CvMat* Merode = Pointer to morphological processed matrix. 
    */ 
    
    
    
        CvMat* Merode = cvCreateMat(h,w,CV_8UC1); 
        . 
        . 
        . 
        . 
        . 
        . 
        
        
        
        ///// Releasing the images, matrices and structuring elements to free memroy. 
       // Matrix Merode is not released as it is the output of this funtion file 
        cvReleaseStructuringElement(&B); 
        cvReleaseMat( &Mopen ); 
        cvReleaseMat( &temp ); 
        cvReleaseMat( &Mclose ); 
        cvReleaseMat( &temp1 ); 
        cvReleaseMat( &MM ); 
        cvReleaseImage( &img1 ); 
        cvReleaseMemStorage(&g_storage); 
        cvReleaseMat( &Mimg1 ); 
        cvReleaseMat( &Mimg2 ); 
    
    
        return Merode; 
    } 

How can I delete Merode ? 
Thank you very much for your help.

