[doc fix] Add operation of freeing output SQLDA
Hello
I think it is better to add freeing operation of output SQLDA to the current PostgreSQL documentation.
As far as I can see src/interfaces/ecpg/ecpglib/execute.c,
if a previously existing sqlda is set to output SQLDA,
then a previously existing sqlda is freed.
But, the new output SQLDA's memory space remain.
ecpg regression test also free output SQLDA's memory space.
The attached patch fixes the documentation.
regards,
--
Kato Sho
Attachments:
sqlda_doc.patchapplication/octet-stream; name=sqlda_doc.patchDownload
diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index 98b6840..84c7bf0 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -3891,7 +3891,7 @@ EXEC SQL DESCRIBE prepared_statement INTO mysqlda;
<step><simpara>Fetch rows from the cursor, and store them into an output SQLDA.</simpara></step>
<step><simpara>Read values from the output SQLDA into the host variables (with conversion if necessary).</simpara></step>
<step><simpara>Close the cursor.</simpara></step>
- <step><simpara>Free the memory area allocated for the input SQLDA.</simpara></step>
+ <step><simpara>Free the memory area allocated for the input and output SQLDAs.</simpara></step>
</procedure>
<sect3>
@@ -4210,6 +4210,12 @@ switch (v.sqltype)
}
</programlisting>
</para>
+ <para>
+ Finally after using output SQLDA, the allocated memory space must be freed explicity.
+<programlisting>
+free(sqlda1);
+</programlisting>
+ </para>
</sect3>
<sect3 id="ecpg-sqlda-input">
@@ -4290,8 +4296,7 @@ EXEC SQL OPEN cur1 USING DESCRIPTOR sqlda2;
<para>
Finally, after using input SQLDAs, the allocated memory space
- must be freed explicitly, unlike SQLDAs used for receiving query
- results.
+ must be freed explicitly.
<programlisting>
free(sqlda2);
</programlisting>
@@ -4583,6 +4588,7 @@ main(void)
}
}
+ free(sqlda1);
EXEC SQL CLOSE cur1;
EXEC SQL COMMIT;
Hello.
At Fri, 18 May 2018 06:03:59 +0000, "Kato, Sho" <kato-sho@jp.fujitsu.com> wrote in <25C1C6B2E7BE044889E4FE8643A58BA963A42097@G01JPEXMBKW03>
Hello
I think it is better to add freeing operation of output SQLDA to the current PostgreSQL documentation.
As far as I can see src/interfaces/ecpg/ecpglib/execute.c,
if a previously existing sqlda is set to output SQLDA,
then a previously existing sqlda is freed.
But, the new output SQLDA's memory space remain.
I didn't look it closer but generally speaking output sqlda
should be freed automatically (or by ecpg API) since users don't
know it in detail. It is a linked list so just freeing the first
one is not sufficient(*1). On the other hand ecpg library cannot
free input sqlda since it doesn't know how it was provided. Thus
I'm on the documentation side. I'm not sure of the reason for
freeing output sqlda explicitly in the test code, maybe it is to
avoid valgrind complaint or such like..
I think if output sqlda is not freed and finally orphaned after
correct API usage, it should be fixed. I suppose that EXEC SQL
DEALLOCATE DESCRIPTOR is responsible..
ecpg regression test also free output SQLDA's memory space.
The attached patch fixes the documentation.
*1: The test code knows the shape exactly so it can properly free
them in proper way.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Thank you for your reply.
I didn't look it closer but generally speaking output sqlda should be freed automatically (or by ecpg API) since users don't know it in detail.
I think output sqlda should automatically.
But, it is difficult, because ecpg does not know which output sqlda can be freed.
Since the cursor does not know which sqlda is used, it is not possible to automatically free the output sqlda when the cursor is closed.
Probably it is the same at other timing.
I think if output sqlda is not freed and finally orphaned after correct API usage, it should be fixed. I suppose that EXEC SQL DEALLOCATE DESCRIPTOR is responsible..
I think DEALLOCATE DESCRIPTOR is for named sql descriptor.
ecpglib manages the descriptor in the linked list.
When DEALLOCATE DESCRIPTOR is called, ecpglib seaches the linked list using the name of the descriptor as a key and free the descriptor.
So, simply DEALLOCATE DESCRIPTOR cannot be used for sqlda.
If free is undesirable, how would you think to make an ecpg API for free?
regards,
-----Original Message-----
From: Kyotaro HORIGUCHI [mailto:horiguchi.kyotaro@lab.ntt.co.jp]
Sent: Tuesday, May 22, 2018 10:51 AM
To: Kato, Sho/加藤 翔 <kato-sho@jp.fujitsu.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: [doc fix] Add operation of freeing output SQLDA
Hello.
At Fri, 18 May 2018 06:03:59 +0000, "Kato, Sho" <kato-sho@jp.fujitsu.com> wrote in <25C1C6B2E7BE044889E4FE8643A58BA963A42097@G01JPEXMBKW03>
Hello
I think it is better to add freeing operation of output SQLDA to the current PostgreSQL documentation.
As far as I can see src/interfaces/ecpg/ecpglib/execute.c,
if a previously existing sqlda is set to output SQLDA, then a
previously existing sqlda is freed.
But, the new output SQLDA's memory space remain.
I didn't look it closer but generally speaking output sqlda should be freed automatically (or by ecpg API) since users don't know it in detail. It is a linked list so just freeing the first one is not sufficient(*1). On the other hand ecpg library cannot free input sqlda since it doesn't know how it was provided. Thus I'm on the documentation side. I'm not sure of the reason for freeing output sqlda explicitly in the test code, maybe it is to avoid valgrind complaint or such like..
I think if output sqlda is not freed and finally orphaned after correct API usage, it should be fixed. I suppose that EXEC SQL DEALLOCATE DESCRIPTOR is responsible..
ecpg regression test also free output SQLDA's memory space.
The attached patch fixes the documentation.
*1: The test code knows the shape exactly so it can properly free
them in proper way.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center