Python Forum
trace invalid pointer - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: trace invalid pointer (/thread-17540.html)



trace invalid pointer - simon149 - Apr-15-2019

Hello

I am using a python program i have writtent to collect machine data and send it via a socket to a server, the program does what it is supposed to do for 99% of the time but occasionally i am getting an error "*** Error in '/user/bin/python3': free(): invalid pointer: 0x00405340 ***"

After reserching this i am getting some quite complex information that is above my experience and have no way of tracing the root cause as when it happens it just crashes out to terminal window with the error message.

My skills are limited with Python but what i am looking for is an ability to trace the source/cause of the crash, this way i can resolve the issue, i am not looking for a solution to the cause just the route to find the problem if that makes sense?

What is the best way to find the line of code that has caused this error?

I have not posted any code as there are multiple modules, some compiled that i have imported from 3rd parties etc and to be honest i have no idea what code to post without an indication of the root cause?

Any pointers (that are not invalid Big Grin ) greatly appreciated

Thanks
Simon


RE: trace invalid pointer - Larz60+ - Apr-15-2019

Post code of module causing error


RE: trace invalid pointer - simon149 - Apr-15-2019

(Apr-15-2019, 08:56 AM)Larz60+ Wrote: Post code of module causing error

Hi
The problem i have is i dont know what module it is because when is crashes out i have no way to trace the line or module that i am aware of?


RE: trace invalid pointer - Larz60+ - Apr-15-2019

At least show full error traceback.


RE: trace invalid pointer - simon149 - Apr-15-2019

(Apr-15-2019, 11:24 AM)Larz60+ Wrote: At least show full error
I cannot see any traceback, just 1 line "*** Error in '/user/bin/python3': free(): invalid pointer: 0x00405340 ***"
Is this a problem happening outside of my programs but caused by the program, therefore no traceback?
As this is happening about 2 or 3 times a week across about 10 units i have to reset them as soon as it occures to keep the data flowing, i cannot recreate the problem as i do not know the root cause?

I can see that this looks like i am asking people to help me solve a problem with no information, the problem is i am unclear as to where to get the information from?
After a crash if there is no informationcaught by the program and nothing except the one line below showing in the terminal is it possible to get any trace information from elsewhere?

Simon
ps i have a .png of the terminal window on crash but no ability to post it.


RE: trace invalid pointer - ichabod801 - Apr-15-2019

What packages are you importing into your code? I'm wondering if there is a non-standard package you are using that is causing the problem. Otherwise it would be something wrong with Python itself. It does sound like it is outside of your program, which would mean filing a bug report with the appropriate developers.

One way you could narrow down the source of the problem is with print lining. Just print every few lines what is being done at that point. Then the last print you see will give you a basic idea of where the problem is. Of course, if the volume of data you are process is large, this might not be viable.


RE: trace invalid pointer - simon149 - Apr-15-2019

I am using FRAM memory to store values in and i have just noticed that i have not got any error trapping in that module, i am also using a 3rd party module, not sure if this could be a problem but it looks straight forward enough, below that i have also included my code for reading and writing to the FRAM, just started to add error trapping, not completed write section yet(apologies for any poor programming but i am learning Python)

#!/usr/bin/env python

# SDL_Pi_FRAM.py Python Driver Code
# SwitchDoc Labs 02/16/2014
# V 1.2


from datetime import datetime

import time
import smbus



class SDL_Pi_FRAM():
    

###########################
# SDL_Pi_FRAM Code
###########################
    def __init__(self, twi=1, addr=0x50):
        self._bus = smbus.SMBus(twi)
        self._addr = addr



    def write8(self, address, data):
        #print "addr =0x%x address = 0x%x data = 0x%x  " % (self._addr, address, data)
        self._bus.write_i2c_block_data(self._addr,address>>8, [address%256, data])



    def read8(self, address):

        self._bus.write_i2c_block_data(self._addr,address>>8, [address%256])
        returndata = self._bus.read_byte(self._addr) # this will read at the current address pointer, which we on the previous line
        #print "addr = 0x%x address = 0x%x %i returndata = 0x%x " % (self._addr, address, address, returndata)
        return returndata
import sys
import SDL_Pi_FRAM
import glob as gn
import time
import datetime
import logging
 
logging.basicConfig(level=logging.ERROR,
                    format='%(asctime)s %(levelname)s %(message)s',
                    filename='/home/pi/share/Data_Collection/errlog.log',
                    filemode='a')

def W():
    def MEMWrite (x,y,z):

        for q in range (y,z): #clear slot first
            fram.write8(q, 0)

            
        for letter in str(x):
            fram.write8(y, ord(letter))
            y+=1


    #print(time.time())

    fram = SDL_Pi_FRAM.SDL_Pi_FRAM(addr = 0x50)

    try:
        MEMWrite(gn.batchA,0,9)
    except BaseException as e:
        logging.error("FRAM Memory write error for batchA " + str(e))
    
        
        
    MEMWrite(gn.batchB,10,19)
    MEMWrite(gn.totalA,20,29)
    MEMWrite(gn.totalB,30,39)
    MEMWrite(gn.Job,40,49)
    MEMWrite(gn.TargetCycle,50,59)
    MEMWrite(gn.MachineName,60,69)
    MEMWrite(gn.ShiftCyclesInAuto,70,79)
    MEMWrite(gn.Shift,80,89)
    MEMWrite(gn.QtyShiftMade,90,99)
    MEMWrite(gn.ShiftDateTime,100,119)
    MEMWrite(gn.PartCode,120,169)
    MEMWrite(gn.myStatus,170,179)

    #print(time.time())
def R():
    def MEMRead (y,z): #value, start memory, end memory
        myStr=""
        for a in range(y,z):
            v=chr(fram.read8(a))
            if ord(v)!=0:  #if char is not "_" as this is used to clear locations
                myStr+=v
        return myStr

    fram = SDL_Pi_FRAM.SDL_Pi_FRAM(addr = 0x50)
    try:
        gn.batchA=int(MEMRead(0,9))
    except ValueError:
        gn.batchA=0
        logging.error("FRAM Memory read error for BatchA " + str(ValueError))
    try:
        gn.batchB=int(MEMRead(10,19))
    except ValueError:
        gn.batchB=0
        logging.error("FRAM Memory read error for BatchB " + str(ValueError))
    try:
        gn.totalA=int(MEMRead(20,29))
    except ValueError:
        gn.totalA=0
        logging.error("FRAM Memory read error for totalA " + str(ValueError))
    try:
        gn.totalB=int(MEMRead(30,39))
    except ValueError:
        gn.totalB=0
        logging.error("FRAM Memory read error for totalB " + str(ValueError))
    try:
        gn.Job=MEMRead(40,49)
    except ValueError:
        gn.Job='000000'
        logging.error("FRAM Memory read error for Job " + str(ValueError))
    try:
        gn.TargetCycle=MEMRead(50,59)
    except ValueError:
        gn.TargetCycle=0.0
        logging.error("FRAM Memory read error for TargetCycle " + str(ValueError))
    try:
        gn.MachineName=MEMRead(60,69)
    except ValueError:
        gn.MachineName='Not Set'
        logging.error("FRAM Memory read error for MachineName " + str(ValueError))
    try:
        gn.ShiftCyclesInAuto=MEMRead(70,79)
    except ValueError:
        gn.ShiftCyclesInAuto=0
        logging.error("FRAM Memory read error for ShiftCyclesInAuto " + str(ValueError))
    try:
        gn.Shift=MEMRead(80,89)
    except ValueError:
        gn.Shift='?'
        logging.error("FRAM Memory read error for Shift " + str(ValueError))
    try:
        gn.QtyShiftMade=MEMRead(90,99)
    except ValueError:
        gn.QtyShiftMade=0
        logging.error("FRAM Memory read error for QtyShiftMade " + str(ValueError))
    try:
        gn.ShiftDateTime=MEMRead(100,119)
    except ValueError:
        gn.ShiftDateTime=str(datetime.date.today())
        logging.error("FRAM Memory read error for ShiftDateTime " + str(ValueError))
    try:
        gn.PartCode=MEMRead(120,169)
        if gn.PartCode=='':
            gn.PartCode='No Part Code Set'
    except ValueError:
        gn.PartCode='No PartCode Set'
        logging.error("FRAM Memory read error for PartCode " + str(ValueError))
    try:
        gn.myStatus=MEMRead(170,179)
        if gn.myStatus=='':
            gn.myStatus='7' 
    except ValueError:
        gn.myStatus='7'
        logging.error("FRAM Memory read error for Status " + str(ValueError))
    



RE: trace invalid pointer - simon149 - Apr-16-2019

(Apr-15-2019, 02:49 PM)simon149 Wrote: chabod801 wrote Yesterday, 06:09 PM:
Use Python tags (the python logo button) for blocks of code. The icode tags ([] button) is for inline code

Got it, thanks
Simon