ibmdb / python-ibmdb

Automatically exported from code.google.com/p/ibm-db
Apache License 2.0
308 stars 191 forks source link

malloc error: pointer being freed was not allocated #705

Closed arlon-nlo closed 2 years ago

arlon-nlo commented 2 years ago

After reinstalling the idmdb2 package, this symbol not found error disappeard (https://github.com/ibmdb/python-ibmdb/issues/691). However, a new error occures when call the ibm_db.connect function:

python(2472,0x201366600) malloc: *** error for object 0x7ffb559e3800: pointer being freed was not allocated python(2472,0x201366600) malloc: *** set a breakpoint in malloc_error_break to debug

I'm running OSX Monterey and Python 3.9 via Anaconda.

bimalkjha commented 2 years ago

@arlon-nlo Are you sure this error is from ibm_db and not from the python? Please share the stack trace. I think it is something related with application code. Check the similar python issue discussed here Thanks.

arlon-nlo commented 2 years ago

@bimalkjha The exact same code runs perfectly on my older Macbook, with an older version of OSX.

On Monterey, this code:

import ibm_db
conn_a = ibm_db.connect("<server info>;", "", "")

returns

python(3071,0x201800600) malloc: *** error for object 0x7ffb559e3800: pointer being freed was not allocated
python(3071,0x201800600) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort
amukherjee28 commented 2 years ago

@arlon-nlo

I tested the same in very similar environment.

Python 3.9 from anaconda distribution

 python
Python 3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

First I installed ibm_db package using

conda install ibm_db

Tested connection through a sample program

python error1.py
=> Creating the connection
=> Connected to Server ... SUCCESSFULL

CODE

print("=> Creating the connection")
try:
    connection = ibm_db.connect(conn_str,"","")
    print("=> Connected to Server ... SUCCESSFULL")
except:
    print("=> Connection to server .... FAILED")
    print("Error Description = " + ibm_db.conn_errormsg())
    print("SQLSTATE = " + ibm_db.conn_error())
    exit(0)

The same sample also worked when I installed ibm_db using

pip install ibm_db

I am also running these in MacOS Monterey.

Could you please uninstall and clean the previous installation properly and install again check. While uninstall could you check if the clidriver is removed properly, so that when you install fresh the new clidriver is placed in the installed folder, since for mac we had made changes in the clidriver it is very important that it gets installed properly.

arlon-nlo commented 2 years ago

@amukherjee28 I ran pip uninstall ibm_db, removed the complete clidriver folder from the site-packages and then ran install ibm_db --no-cache-dir. The error remains the same. Installing via conda did not work PackagesNotFoundError: The following packages are not available from current channels: ibm_db. I have an Apple Silicon machine, could it be due to that?

amukherjee28 commented 2 years ago

In the conda install command you have to include the channel as well

conda install -c conda-forge ibm_db

Coming to MacOS version we are still waiting for testing the driver in Apple M1 Chip system. It may be an OS thing (possibly) which we have to investigate. We have not yet certified the same from our end as of now.

arlon-nlo commented 2 years ago

@amukherjee28 thanks for the help so far. Unfortunately, the same error remains with conda install -c conda-forge ibm_db. I will run the code in a cloud environment for now. Hopefully there will be a solution for this in the future.

amukherjee28 commented 2 years ago

As soon we test it in the new OS I will update this issue. I have tagged this as new OS support for now.

Dagdelo commented 2 years ago

Same error here.

amukherjee28 commented 2 years ago

@Dagdelo @arlon-nlo

Could you please try setting the DYLD_LIBRARY_PATH to the lib folder of the clidriver and check again. I had the issue initially for some people in Monterey and seems that this approach worked for them.

Just try and set the following path

export DYLD_LIBRARY_PATH=<full path to clidriver>/lib:$DYLD_LIBRARY_PATH

Please let me know if this works for now.

Thanks

Dagdelo commented 2 years ago

I installed ibm_db from pip, but I'm not sure if this command should do the trick: export DYLD_LIBRARY_PATH = $IBM_DB_HOME/lib:$DYLD_LIBRARY_PATH

arlon-nlo commented 2 years ago

@amukherjee28 @Dagdelo just tested this, but it doesn't work. I'm also quite sure that the correct clidriver folder is found, because when I delete that folder, other errors pop up.

amukherjee28 commented 2 years ago

I was referring to the issue #648 where the same solution worked out for various users.

Hence I though of referring the same here.

Dagdelo commented 2 years ago

Thx @amukherjee28 , but the issue remains. Unfortunately.

instakarlo commented 2 years ago

Any updates on this, we are also having errors in our Mac Python runs. Tried the setting of DYLD_LIBRARY_PATH, installing new gcc, reinstalling (clean install) of ibm_db and it does not work :<

I shouldn't have upgraded to Monterey OS :<

amukherjee28 commented 2 years ago

@instakarlo

You should not face the above issue if you are in MAC OS Monterey.

You may try cleaning up the previous installation and install again in order to get the new clidriver along with the installation. We have upgraded the clidriver to work with Monterey OS.

We are suspecting issues in Apple M1 Chip as we have not tested our driver against the same.

Dagdelo commented 2 years ago

@amukherjee28 I'm on MacOS 12.1 Monteray. Intel chip. Fresh installation (ibm-db v3.1.0 and ibm-db-sa 0.3.7). Python 3.10.7 . Using the DYLD_LIBRARY_PATH env var to the pip lib... Same error.

instakarlo commented 2 years ago

@instakarlo

You should not face the above issue if you are in MAC OS Monterey.

You may try cleaning up the previous installation and install again in order to get the new clidriver along with the installation. We have upgraded the clidriver to work with Monterey OS.

We are suspecting issues in Apple M1 Chip as we have not tested our driver against the same.

Hi, here are the steps that I did:

  1. Since I am running on virtual environment (venv), I deleted this to create a fresh install
  2. Create virtual environment (venv)
  3. Install libs using requirements.txt (ibm-db==3.1.0)
  4. Run

Result:

Python(3795,0x700011a32000) malloc: *** error for object 0x7ffb44973e00: pointer being freed was not allocated
Python(3795,0x700011a32000) malloc: *** set a breakpoint in malloc_error_break to debug

It breaks on this line:

connDetails= = ibm_db.connect(connectStr, '', '')

It works before Monterey Upgrade, I did not do any change... Am I doing something wrong? TY!

katepapineni commented 2 years ago

@amukherjee28 @bimalkjha

Hi I am facing this issue as well when trying to call ibm_db.pconnect on macOS Monterey version 12.0.1 Intel chip, Python version 3.9.9 and fresh install of ibm-db==3.1.1, how can I resolve this? Thanks.

katepapineni commented 2 years ago

@amukherjee28 @bimalkjha

Hi I am facing this issue as well when trying to call ibm_db.pconnect on macOS Monterey version 12.0.1 Intel chip, Python version 3.9.9 and fresh install of ibm-db==3.1.1, how can I resolve this? Thanks.

Okay finally got this working, updated the version of gcc/g++ on my Mac using brew update gcc (gcc: stable 11.2.0). Then uninstalled/reinstalled ibm-db 3.1.1 and then also ran the command to update the DYLD_LIBRARY_PATH env variable:

export DYLD_LIBRARY_PATH=/usr/local/lib/python3.9/site-packages/clidriver/lib:$DYLD_LIBRARY_PATH
instakarlo commented 2 years ago

I fixed mine also, had to manually update the .venv/bin/activate to add the DYLD_LIBRARY_PATH .. just weird since I haven't done this before before Monterey upgrade

Dagdelo commented 2 years ago

I tried to reproduce the fix several times with differents python versions. Can someone please help me how to do it? I'm using the pyenv-virtualenv. This is my $DYLD_LIBRARY_PATH: export DYLD_LIBRARY_PATH=/Users/henriquedelgadosales/.pyenv/versions/venv-II-API/lib/python3.9/site-packages/clidriver.

My pip list | grep "ibm":

ibm-db 3.1.0 ibm-db-sa 0.3.7

My output whe trying to run the app:

sql_select : DEBUG connecting with Engine(db2://db2inst1:@...;) 2022-01-17 11:15 sql_select DEBUG connecting with Engine(db2://db2inst1:@...;) python(43302,0x10e0a6600) malloc: error for object 0x7ffb47865300: pointer being freed was not allocated python(43302,0x10e0a6600) malloc: set a breakpoint in malloc_error_break to debug [3] 43302 abort python data-api/run.py

Double checked env:

echo $DYLD_LIBRARY_PATH /Users/henriquedelgadosales/.pyenv/versions/venv-II-API/lib/python3.9/site-packages/clidriver

instakarlo commented 2 years ago

I tried to reproduce the fix several times with differents python versions. Can someone please help me how to do it? I'm using the pyenv-virtualenv. This is my $DYLD_LIBRARY_PATH: export DYLD_LIBRARY_PATH=/Users/henriquedelgadosales/.pyenv/versions/venv-II-API/lib/python3.9/site-packages/clidriver.

My pip list | grep "ibm":

ibm-db 3.1.0 ibm-db-sa 0.3.7

My output whe trying to run the app:

sqlselect : DEBUG connecting with Engine(db2://db2inst1:@...;) 2022-01-17 11:15 sql_select DEBUG connecting with Engine(db2://db2inst1:_@...;) python(43302,0x10e0a6600) malloc: error for object 0x7ffb47865300: pointer being freed was not allocated python(43302,0x10e0a6600) malloc: set a breakpoint in malloc_error_break to debug [3] 43302 abort python data-api/run.py

Double checked env:

echo $DYLD_LIBRARY_PATH /Users/henriquedelgadosales/.pyenv/versions/venv-II-API/lib/python3.9/site-packages/clidriver

For me I did the following (but not sure if it'll work in your environment since different people have different solutions):

I upgraded gcc using brew update gcc I upgraded my ibm_db to 3.1.1 in requirements file and did a new install in virtual env then deactivate virtual env again

Before I activate my virtual env again, I ran (check ur path seems different paths for different people) export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/clidriver/lib

Then I modified .venv/bin/activate to add the following lines: export DYLD_LIBRARY_PATH="$VIRTUAL_ENV/lib/clidriver/lib"

After that I activate my virtual env: source .venv/bin/activate

Also, Mac is asking for another upgrade, but I think I won't upgrade for now

good luck!

bimalkjha commented 2 years ago

@instakarlo @Dagdelo This issue should be fixed now. If you still face it, please delete the clidriver directory /Users/henriquedelgadosales/.pyenv/versions/venv-II-API/lib/python3.9/site-packages/clidriver and go for fresh installation. Issue should be fixed now. If still you see any problem, then rename clidriver\lib\libstdc++.* library. It should be good. Thanks.

bimalkjha commented 2 years ago

See similar issue reported for other driver: https://github.com/ibmdb/node-ibm_db/issues/824