[Libaps-general] sysAPS problem.
Brought to you by:
brianpirie,
tranter
From: Mark P. <mp...@va...> - 2000-09-05 21:41:39
|
Hi all, I could use a little help here. It may well be that I'm doing something wrong, but I seem to have a memory leak. I've reduced it down to a small test case, and was hoping you could look at what I'm doing and see the problem. I compile the attached C program with this command line: gcc -g -Wall -laps aps_test.c -o prntest Run it with a valid printer queue as the sole parameter: ./prntest lp0 Output will be the virtual memory size (from /proc) for the process, and the difference from the previous iteration, like this: $ ./prntest hp4050 Total Virtual: 1712128 Change: 1712128 Total Virtual: 1716224 Change: 4096 Total Virtual: 1720320 Change: 4096 Total Virtual: 1724416 Change: 4096 Total Virtual: 1724416 Change: 0 Total Virtual: 1728512 Change: 4096 Total Virtual: 1728512 Change: 0 Total Virtual: 1732608 Change: 4096 Total Virtual: 1736704 Change: 4096 Total Virtual: 1736704 Change: 0 Total Virtual: 1740800 Change: 4096 Total Virtual: 1740800 Change: 0 .... This example was from a queue that had six jobs. Because I'm getting info out of the /proc file system, this will need to be run under Linux. I've noticed that it leaks memory faster the more items are in the queue. Thanks in advance for any help you can give me. Please let me know if I'm doing something stupid in the code. The code is appended to the end of this message. -- ------------------------------------------------------ Mark Pruett VA Linux Systems mp...@va... Open Source Printing ------------------------------------------------------ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <aps.h> /*------------------------------------------------------------------- -------------------------------------------------------------------*/ void test (char *queue) { Aps_QueueHandle globalQueueHandle; Aps_Result result; Aps_PrinterHandle printerHandle = NULL; char tempstr [1024]; int heap = 0; static int pheap = 0; FILE *pipe; if (Aps_OpenPrinter (queue, &printerHandle) == APS_SUCCESS) { if ((result = Aps_PrinterOpenQueue (printerHandle, &globalQueueHandle)) == APS_SUCCESS) { // printf ("Got printer queue from handle.\n"); } } if (Aps_Succeeded(result)) { Aps_QuickPrinterQInfo **printerQInfo; int numElements; result = Aps_QueueMakeQuickPrinterQInfoArray(globalQueueHandle, &printerQInfo, &numElements); /* Report the change in virtual memory. */ sprintf (tempstr, "cat /proc/%d/stat | cut -d ' ' -f 23", getpid()); pipe = popen (tempstr, "r"); fgets (tempstr, 1024, pipe); heap = atoi (tempstr); printf ("Total Virtual: %d Change: %d\n", heap, heap-pheap); pclose (pipe); pheap = heap; Aps_ReleaseBuffer (printerQInfo); Aps_ReleaseHandle(printerHandle); Aps_ReleaseHandle(globalQueueHandle); } } /*------------------------------------------------------------------- -------------------------------------------------------------------*/ int main (int argc, char ** argv) { if (argc != 2) { printf ("Expected a printer queue parameter.\n"); return 0; } while (1) { test (argv[1]); sleep (1); } return 0; } |