This may be some what long winded and complex, but the basic issue here is a memory leak somewhere in my C Perl interface.

A little background. I have a Perl database that has a basic list of MQ Queue names and individual users. The process that is causing issues is taking information and routing it from the user to the Queue. From what I have seen my embedding is working fine apart from this memory problem. We are running on a AIX platform under tuxedo (Yucky I know but you got to work with the tools they give you!) The Embedding code looks like this...
#include <EXTERN.h> #include <perl.h> #include <stdio.h> #include <stdlib.h> static PerlInterpreter *my_perl; int count; int counter; char *queue; char *tempPop; char *temp; int i = 0; EXTERN_C void xs_init _((void)); EXTERN_C void boot_DynaLoader _((CV* cv)); EXTERN_C void xs_init(void) { char *file = __FILE__; dXSUB_SYS; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); } /********************************************************************* +*******/ /* PERL Database interface subroutine, should return an array of queue + names*/ /********************************************************************* +*******/ Perldatabase(char pseudo [6], char *queue) { dSP; ENTER; SAVETMPS; PUSHMARK (SP); XPUSHs (sv_2mortal (newSVpv (pseudo,6))); PUTBACK; perl_call_pv("database", G_ARRAY); SPAGAIN; count = POPi; temp=queue; while (count !=0) { tempPop = POPp; memcpy (temp, tempPop, 10); count--; temp = temp+10; } PUTBACK; FREETMPS; LEAVE; } char* interface(char pseudo[6], char *queue) { char *my_argv[] = { "", "dataquery.pl"}; my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, xs_init, 2, my_argv, (char **)NULL); perl_run(my_perl); Perldatabase(pseudo, queue); perl_destruct (my_perl); perl_free(my_perl); return (queue); }
And the perl script running looks like this
#!/usr/bin/perl use SDBM_File; use POSIX; sub database { my ($pseudo) = @_; %dbm; $db_file = "CTIC.dbm"; tie %dbm, 'SDBM_File', $db_file, O_RDWR, 0; #open read only @list=split ("__",$dbm{"$pseudo"}); $count = 0; foreach $item(@list) { $queue1 = $item; $count++; } untie %dbm; @list2 =(@list,$count); return @list2; }
Now I am by no means a Perl expert - this is my first Perl venture, but is there anyway to see what is leaking memory? Anyway to fix it? Anything obvious that you guys see? Any tools out there to help with this sort of thing? Anything????

Note I believe we are still running on 5.00503 if that makes any difference to this???

Many thanks for your time in advance, I apologise for the many questions, any insight would be greatly appricated.

Tom

In reply to Memory leak issue with Embedded Perl by tomw1975

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.